After my player dies, I use transform.position to move it back to the respawn point.
transform.position = RespawnPoint;
The problem is, it still retains its velocity from before it died.
This often causes it to fall off the platform again! Please Help!
If your player is using a Rigidbody/Rigidbody2D for movement, just set its velocity to 0 when they die or respawn.
I just need to ask this for my game, but, does an object with a Kinematic RigidBody2D type and a box collider collide with another box?
Yes. Non-trigger colliders will always collide with other colliders unless explicitly disabled in the physics collision matrix.
Only specific Rigidbody2D types (and their colliders) will interact. If you want to know what body-types can collide with other body-types then you can find that info here (see “Collision action matrix” section).
FYI: You should not be modifying the Transform when using Rigidbody2D or any other 2D physics component. By adding a Rigidbody2D you’re putting it in control of the Transform so you’re bypassing it by doing that. The Rigidbody2D has its own API for doing this i.e. its position, velocity etc.
Thanks Vryken and MelvMay
I am now using:
rb.position = respawnPoint;
rb.velocity = new Vector2(0,0);
Cool.
Note that there’s a shortcut for zero on a Vector2 here,
GetComponent<Rigidbody2D>().velocity = Vector3.zero;
Sets the rigidbody velocity to zero
No, you should use Vector2.zero (rather than relying on Unity implicitly converting your incorrect type to the correct one) as stated in my post before your thread necro.