How to slow down a Rigidbody2D
Hey I am trying for slowing my player down this is the code I'm useing:
Rigidbody2D rb2d;
void FixedUpdate () {
rb2d = GetComponent<Rigidbody2D>();
if (Input.GetKey(KeyCode.W)) {
this.rb2d.AddForce(transform.up * _speed / 2);
}
if (Input.GetKey(KeyCode.A)) {
transform.Rotate(Vector3.forward * 0.75f * _speed);
}
if (Input.GetKey(KeyCode.D)) {
transform.Rotate(Vector3.forward * -0.75f * _speed);
}
if () {
Debug.Log("DownKey");
}
this.rb2d.velocity = this.rb2d.velocity * 0.9;
}
I get the error: error CS0019: Operator '*' cannot be applied to operands of type 'UnityEngine.Vector2' and 'double'
Answer by gcoope · Apr 26, 2016 at 08:28 AM
Try change 0.9 to 0.9f on the final line. You're only able to multiply a Vector2 or 3 by a float, but in C# having a decimal - e.g. 0.9 - is treated as a double unless you append the f to make it a float.
does specifying it as a 0.9f not fix the issue/ error?
Thanks for $$anonymous$$ding me of the 0.9f now it works :D
Your answer
Follow this Question
Related Questions
Simple issue with the structure of C# rigidbody2D code 1 Answer
How do i take a grab of clone from prefab and change his velocity 2 Answers
Why my Player GameObject keeps on mooving anyway on its own without my input? 1 Answer
2D Rigidbody Velocity Being Weird 1 Answer
Rigidbody2D won't move player 0 Answers