Hey i’m very new to unity and am currently just trying to do a simulation where a ball rolls down a ramp and knocks over some boxes. What i want to do is display the velocity of the ball but i dont know how and all the documentation is very confusing with people just giving small lines of code and not a full solution where i can see what to do. Thanks for any help ![]()
2 Answers
2Try this:
public GameObject ball;
void Update () {
Debug.DrawRay(ball.transform.position, ball.GetComponent <Rigidbody> ().velocity, Color.Red, 0.01f);
}
This should draw a red line in the direction of the ball’s velocity. If you want each line to last longer, just increase the last value (it’s the survival time in seconds).
Hope this helps!

You're missing something at the beginning: using System.Collections; using System.Collections.Generic; using UnityEngine; That's why everything doesn't work. Also, don't include the Start function if you aren't going to use it. It's a waste of space.
– DawdleDevthankyou, i think it works but not in the game. Also is there any way to display its speed in say a text box? like in a car for example? thankyou!
– Georgegohl888