Resetting momentum from respawned object?
Hi there, I'm using a basic script to respawn a ball falling with gravity, but one it collides with an object below it, after hitting the trigger below, it keeps the same momentum that it had while falling, and respawns travelling at the same speed and angle from the respawn point I set. I just based it off this video here: https://www.youtube.com/watch?v=nBgCeJBMT0k.
I want it to reset before it drops down again, with it falling very straight down, rather than with the momentum.
Here's my script, any help would be super!! I'm a very novice coder and new to Unity too, so if you could explain as easily as possible, that would be great!
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Respawn : MonoBehaviour { public Rigidbody rb;
[SerializeField]private Transform sphere;
[SerializeField]private Transform respawnPoint;
void Start() {
rb = GetComponent<Rigidbody>();
}
void FixedUpdate() {
if (Input.GetButtonDown ("up"))
rb.isKinematic = true;
rb.isKinematic = false;
}
// Use this for initialization
void OnTriggerEnter (Collider other) {
sphere.transform.position = respawnPoint.transform.position;
}
}
Answer by Dragate · Oct 26, 2017 at 08:49 AM
On respawn, also do
rb.velocity = Vector3.zero;
rb.angularVelocity = Vector3.zero;
Your answer
Follow this Question
Related Questions
Reset Key/Button in unity 5.2? 1 Answer
How to avoid CharacterControllers stepOffset launching my character into space? 1 Answer
Vertical Velocity for fps 0 Answers
C# Trying to make SnowBoarding Like Physics 0 Answers
Death Countdown Area 0 Answers