- Home /
 
Projectile needs to register collisions with rigidbody and non-rigidbodies
I have an arrow that flies in a straight line. It has a script that should apply damage and destroy the arrow when it hits an actor or a wall (or any other obstacle).
Problem:
Since it moves and needs to register collisions, it needs a rigidbody. This means that it will actually push rigidbodies or CharacterControllers (such as actors) away, even if the arrow object is destroyed immediately afterwards. This is not wanted. I could give every actor a seperate trigger collider and make the arrow's rigidbody non-kinematic, but then I can't register collisions vs. non-trigger colliders (such as walls).
So basically the question is, how can is set up the arrow so that it registers collisions with rigidbodiey/CharacterControllers (actors) AND normal (mesh)colliders (walls, obstacles), without pushing the former out of the way (= applying physics)?
Is there a reason you arrow must have a rigid-body? You can always add multiple colliders to ANY object, regardless of weather or not it has a rigidbody component. I will usually add one collider that is a trigger, and one that is not a trigger, if I want to cover all types of possible collisions.
Alternatively, you could set the mass of the arrow to zero, so it does not impart any momentum.
Thanks for the comment. I added a rigidbody because I don't know how else to make a non-static (since it's a moving projectile) object register collisions. So yes, I could add a trigger to my actors and set the arrow's RigidBody to be non-kinematic, but then I'd have to use OnTriggerEnter on the actor's script, and also the arrow wouldn't be able to collide with walls since they can't use a trigger collider. It also seems liek a rigidbody's mass can't be set to exactly zero.
That's true, with two collider types, you would need to override both collision and trigger functions, but so what... put the damage functionality itself in a single private function that you can call from each collision function, with one line.
I still don't understand how the arrow could register collisions with walls and obstacles which can't have trigger colliders :(
Those obstacles must have SO$$anonymous$$E kind of collider, weather a trigger or physics collider- that is unavoidable. Since your arrow will have BOTH a trigger collider AND a physics collider (you will need to add at least one of these colliders manually, using "Add Component"), it can detect collisions for both types.
Your answer
 
             Follow this Question
Related Questions
AddForce doesn't work 4 Answers
Make player walk on sphere planet 2 Answers
Camera Collision Not Working 0 Answers
My 2 Objescts doesnt collide 1 Answer