Question by
irfanabbaxi · Jan 24, 2017 at 03:40 PM ·
vector3
moving one gameobject towards another
How do you move one gameobject in the direction of another gameobject? I don't want to use unity's built in api funcitons. I'm trying to think in terms of vector math that might be involved here.
Comment
Best Answer
Answer by Saad_Khan · Jan 24, 2017 at 04:01 PM
void FixedUpdate()
{
// Calculate direction vector
Vector3 dir = obj1.transfom.position - ob2.transform.position;
// Normalize resultant vector to unit Vector
dir = dir.normalized;
// Move in the direction of the direction vector every frame
obj1.transform.position += dir * Time.deltaTme * speed;
}
Your answer
Follow this Question
Related Questions
Cant Get a Bullet to Shoot (C#) 2 Answers
Split string into three pieces? 1 Answer
Vector3 not an identifier? 1 Answer
Need help with coordinate conversion. 1 Answer
Problem with Crouch Script - 3D C# 2 Answers