Rigidbodies that never push back
Non-kinematic. Google doesn't seem to tell -- has that ever happened?
I'm using the absolute minimum of built-in Unity physics for a platforming engine that I'm trying to keep as reliable as possible. In line with that, I'm trying to get purely passive physics-driven props that only react to the player without ever applying back any force of their own.
Answer by Le-Capitaine · Jan 09, 2016 at 03:32 PM
Self-answering -- found it. Collision.impulse stores the sum of all velocities applied on collision; I apply it, negative, back on my player and my speed seems to remain constant.
void OnCollisionEnter (Collision other) {
if (other.gameObject.tag == "Prop") PropCol (other);
}
void OnCollisionStay (Collision other) {
if (other.gameObject.tag == "Prop") PropCol (other);
}
void PropCol (Collision contact) {
rigidBody.velocity -= contact.impulse;
}
This might work differently for other users, as my props already had very low mass.
Answer by Wideopen411 · Jan 08, 2016 at 03:00 PM
Heres an option, not really sure what you are after though. If the rigidbody doesn't need to interact with the player after the inital hit then;
Make a regular game object, name it Go1 in this instance. Give that game object whatever type of collision you need. Make that collision a trigger. Then Make a duplicate of that gameobject, we will call it Go2 in this instance. Give Go2 whatever collision you need, but have its collision ignore the "player" tag. Give Go2 a rigidbody. Make Go2 a child of Go1. Uncheck Go2 so it is not visible in scene.
Then write a little script that does something like. OnTriggerEnter. SetActive=false on Go1, SetActive Go2=true.
So that way whenever you hit Go1. It immediately disappears and spawns Go2 in its place. Go2 has its own rigidbody, yet it doesn't interact with the player because you told it to ignore "player" collision.
Not just after the hit -- ever. The initial collision might still skew the trajectory and I'd still like props to react after one hit.
Triggers and layers + applying some random velocity on trigger might still be viable, though.
Your answer
Follow this Question
Related Questions
Adding mass to my rigidbody makes it go through the floor 1 Answer
Question about creating a specific first person player prefab 2 Answers
How to make an objects mass increase the longer its air born? 1 Answer
Rigidbodies colliding with each other ignore mass, details inside. 0 Answers
Modifying mass of all objects 1 Answer