About Store Forum Documentation Contact
Donations:
158$/mo



Post Reply 
How to make a character always point in a particular direction
Author Message
Otolone Offline
Member

Post: #1
How to make a character always point in a particular direction
Hi there! I copied this function from a website and modified it.
Class Ai:Game.Chr
{

// O is your object's position
// P is the position of the object to face
// U is the nominal "up" vector

Matrix RotateToFace(Vec O, Vec P, Vec U)
{
Vec D = (O - P);
Vec Right = CrossN(U, D);

Vec Forward = CrossN(Right, U);

Vec Up = Cross(Forward, Right);
Matrix rot = matrix().setRight(Right). setup(Up).setDir(Forward);
return rot;
}

bool update ()
{
Matrix dirMatrix=RotateToFace(pos(),players[0].pos(),matrix().y);
matrix (dirMatrix);
return super.update ();
}


}
This code has strange effects. It causes my Ai to appear below the floor and strange stuff happens.Any help or a different suggestion will give me some sleep.
Thanks.
12-31-2017 03:28 PM
Find all posts by this user Quote this message in a reply
Post Reply