I know I shouldn’t be using Unity 5.5.0f3 however I have gone this far and it is too difficult to start over!
Expected Behavior:
Random movement with the addition of tweak on velocity
Steps to Reproduce:
I have written what Ben has written -
void OnCollisionEnter2D(Collision2D collision)
{
Vector2 tweak = new Vector2(Random.Range(0f, 0.2f), Random.Range(0f, 0.2f));
if (hasStarted)
{
GetComponent<AudioSource>().Play();
rigidbody2D.velocity += tweak;
}
}
rigidbody2D.velocity += tweak; <-- no longer works in Unity 5. I get the error Component rigid2Dbody has been deprecated. Generally when I run into these issues someone has already addressed this issue however I don’t see this issue addressed exactly.
Things I have tried:
- (as suggested by editor) Changed rigidbody2D.velocity += tweak; to…
GetComponent().velocity = new Vector2 () + tweak;
Result - Once the ball collides with anything the ball loses all momentum and comes to a complete stop
- List item
Changed rigidbody2D.velocity += tweak; to…
GetComponent().velocity = new Vector2 (2f, 10f) + tweak;
Result - (same as above) Once the ball collides with anything the ball loses all momentum and comes to a complete stop
-
Finally…
public Rigidbody2D rb;
void Start() {
rb = GetComponent();
}void Update() {
rb.AddForce(transform + tweak);
}
This just gave me errors.
Please help! Thank you!