Shooting doesn't seem to cause damage

AntL

Member
Hi there, I've been working my way through the tutorials for the first person controller. I've a weapon set up correctly as far as I can tell with a muzzle flash and shell cartirdges etc, but for some reason shooting at an object (in this case the red crate prefab) doesn't seem to register any damage (as if the gun isn't shooting). The crate is an instance of the prefab from the demo scene (so I'm assuming it works as expected). Looking at the Shootable Weapon script, it again seems ok but even after select impact layers to everything, it doesnt work (screenshot attached)
1539721238801.png
Any ideas as to where I could have gone wrong?

Thanks
 
I can't see anything wrong there - if you set a breakpoint within ShootableWeapon.HitscanFire and step through the raycast to determine why it's not hitting an object.
 
So I added the line
Code:
  Debug.DrawRay(firePoint, fireDirection * m_HitscanFireRange, Color.red, 3.0f);

1539771133722.png

The hitscan is certainly moving through the object, but not registering a collision. From the line
Code:
  var hitCount = Physics.RaycastNonAlloc(firePoint, fireDirection, m_HitscanRaycastHits, m_HitscanFireRange * strength, m_ImpactLayers.value, QueryTriggerInteraction.Ignore);

...hitCount is still 0. Specifically:
  • firePoint and fireDirection (as you can see from screenshot) are ok;
  • m_HitscanRaycastHits is NULL;
  • m_HitscanFireRange = 100
  • strength = 1
  • m_ImpactLayers.value = -1 (all layers)
...and the object I'm firing at doesn't have IsTrigger ticked (it has a Box Colliser, attribute Manager and Health script). But as I said it's a working prefab from other level. I do however get this error:

UnassignedReferenceException: The variable m_Object of ThirdPersonPerspectiveItem has not been assigned.
You probably need to assign the m_Object variable of the ThirdPersonPerspectiveItem script in the inspector.

I'm really not sure where else to look? Cheers
 
You'll want to get all errors fixed just in case that is preventing something from working. Based off of that error the assault rifle was never assigned to the VIsible Object field of the ThirdPersonPerspectiveItem component.
 
Ah yeah - that was it - assigning the object worked. I didn't previously as I thought it wasn't necessary if I was just using first person. Thanks for your help, much appreciated.
 
Top