Get Speed of moving object without rigidbody in unity3d
Channel:
Subscribers:
1,110
Published on ● Video Link: https://www.youtube.com/watch?v=PaxiYlgLW38
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;
}
}
Other Videos By Muhammad Shahzaib
Tags:
unity
unity3d
learn unity
unity tutorials
speed finding in unity
get speed of object without rigidbody in unity