- Home /
Speed beetween two vectors
Hi there, I need to calculate speed between two points with a certain time. I have vector(start position) and second vector(that player controls). Sometimes second vector can speed up. After 10 sec second vector will stop. I need to get his speed he had in the movement. Any ideas how can I solve this? Thanks
Answer by Jamster · Jan 26, 2014 at 04:01 PM
speed = distance/time :)
The speed is the finalVector - startVector all divided by the time. So:
float speed = ((endVector - startVector) / 10).magnitude;
EDIT: At least I think that's what you're asking... not so sure reading it back :/
Answer by Josie · Jan 26, 2014 at 08:26 PM
Easy all you need to do is get the first position then the position in 10 seconds and subtract those.
Here is an example in JS
var FirstPos : float;
var LastPos : float;
var speed : float;
var time : float;
function Start () { //If you don't want to measure it from the //start then just do an if statement in function Update
FirstPos = transform.position.y; // Or any other axis
}
function Update () {
if(time < 10) {
LastPos = transform.position.y;
speed = FirstPos - LastPos;
}
}
That's not going to find the speed... that'll find the negative delta movement. Speed is measured in metres per second or miles per hour so will need to have time accounted for somewhere in there. Also the OP asked for vectors not floats.
Your answer
Follow this Question
Related Questions
Unity prediction line renderer 0 Answers
Game Objects same transform.position value, sitting on different places 2 Answers
Rigidbody magnitude 3 Answers
Slowing down a fall from a Jump 4 Answers
Charging up the speed of an game object through a mouse click 3 Answers