reset velocity
I am trying to make a flappy bird type game where when I die I get sent back to the menu. But when I click start again the player keeps the downward velocity from the round before making it impossible to regain control of the bird because it falls out of the scene almost immediately.
I´m getting this error when calling rigidbody:
Assets\Scripts\GameOver.cs(20,13): error CS0120: An object reference is required for the non-static field, method, or property 'Rigidbody.velocity'.
This is my script to initiate game over:
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (transform.position.y > 16 || transform.position.y < -7)
{
Rigidbody.velocity = Vector3.zero;
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
}
}
private void OnCollisionEnter(Collision collision)
{
Rigidbody.velocity = Vector3.zero;
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
}
}
Answer by lgarczyn · Jan 26, 2020 at 09:07 PM
Rigidbody with a capital R refers to the class Rigidbody, not the rigidbody of this particular object.
For example, when you call Time.deltaTime, you are not accessing a variable called Time, but a static variable called deltaTime in the class Time.
This is a very important distinction, and I would suggest you read more about c# classes.
Anyway, you're looking for
GetComponent<Rigidbody>().velocity = Vector3.zero;
Your answer
![](https://koobas.hobune.stream/wayback/20220612222149im_/https://answers.unity.com/themes/thub/images/avi.jpg)