Get Speed of moving object without rigidbody in unity3d

Subscribers:
1,110
Published on ● Video Link: https://www.youtube.com/watch?v=PaxiYlgLW38



Duration: 1:46
199 views
10


Code :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpeedFinder : MonoBehaviour
{
public Vector3 lastposition;
public float speed;


// Start is called before the first frame update
void Start()
{
lastposition = transform.position;
}

// Update is called once per frame
void Update()
{
/////////// speed = change in distance/change in time ////////////////
///
speed = (transform.position-lastposition).magnitude/Time.deltaTime;

print(speed);

lastposition = transform.position;

}
}







Tags:
unity
unity3d
learn unity
unity tutorials
speed finding in unity
get speed of object without rigidbody in unity