Answers for "unity get speed of object"

C#
2

unity get speed of object

public float speed;
public float speedPerSecond;
public Vector3 oldPosition;

void Update()
 {
     speed = Vector3.Distance(oldPosition, transform.position); //This is the speed per frames
  	 speedPerSecond = Vector3.Distance(oldPosition, transform.position) / Time.deltaTime; //This is the speed per second
     oldPosition = transform.position;
     Debug.Log("Speed: " + speed.ToString("F2"));
 }
Posted by: Guest on April-18-2021

Code answers related to "unity get speed of object"

C# Answers by Framework

Browse Popular Code Answers by Language