- Home /
Why Rigidbody Collisions Bounce?
Hello Everyone, I'm fairly new to unity so any help would be appreciated.
I currently have an 'NPC' with:
A Rigidbody (1 Mass, 0 Drag, 0 Angular Drag, Use Gravity, and all constraints but the Y Position) and A Box Collider
the npc is controlled with: this.transform.Translate(Vector3.forward * walkSpeed);
Once the player is in range of the npc he will chase after them, My problem is if I have multiple NPC's chasing me and they collide with one another they shoot(or bounce) into the sky? I can provide my code if you would like, However I believe it has to do with the rigidbody, If I set rigidbody.isKinematic = false; then they don't shoot into the sky. However then they don't detect collisions...
I've attempted to google around however most answers didn't really help. If anyone could point me in the right direction I would be grateful, Thanks again.
(I'm using javascript)
Answer by superluigi · Sep 04, 2014 at 04:20 AM
Just talking from experience, although I can be wrong, avoid using translate. Translate makes objects ignore collisions, at least it did every time I used it. For example if you have a floor and you make your character translate down he will go through the floor like it's not even there. Use addforce to push your rigidbody npc in a direction, or you can affect it's velocity directly. It is generally best to avoid messing with a rigidbody's velocity directly because you won't get accurate physics but for what you're trying to do it should be no problem.
These two xample are staight form the scripting reference. You should be able to understand the answer though. In case you're new to all this, addforce will push and the Rigidbody's velocity will climb depending on how much force you add while velocity immediately makes the rigidbody's velocity equal something. rigidbody.AddForce (0, 10, 0); rigidbody.velocity = Vector3(0,10,0);
Thank you for your answer, I don't have the reputation to vote for your answer but I would. You wouldn't have a recommendation to handle the rotation of my NPC would you? Before I would transform.eulerAngles = Vector3(0, Random.Range(0, 360), 0); But as you can imagine this no longer works... Thanks again for your responds, Very helpful.
I usually use transform.rotation = Quaternion.Euler(0, whatever you want here, 0);
Answer by Redeemer86 · Sep 04, 2014 at 04:35 AM
Try setting tags for your enemies and attach scripts which ignore collisions on collision
if(EnemyObject.tag == enemy)
// Ignore Collision maybe using
Your answer
Follow this Question
Related Questions
Ball issue and question 0 Answers
Collisions when pushing object 1 Answer
RigidBody controller - Where to start? 0 Answers