- Home /
How Make an Vector Follow an Quaternion?
**I have a ray that rotates at all angles through the keyboard input my player looks all the time for the ball.
I need to do, the axis "X" and "Z" the vector of the player,
follow the Y-axis ray Quaternion
details:
I want to align the player in the direction of the ray when he's walking with the ball.
details code:
with this code I get the position and rotation of the player and I make it look at the ball
void OnAnimatorMove(){
newPos = anim.rootPosition;
newRot= anim.rootRotation;
//==========================================
if (LookAt_Ball) {
if( info.IsName("WalkBall") && Dist_Player_Ball >0.23
|| info.IsName("Stantard") && Dist_Player_Ball >0.23)
{
Quaternion rotPlayer = Quaternion.LookRotation(newPos - fisicaBola.ArmatureBola.position, Vector3.down);
rotPlayer.x = 0.0F;
rotPlayer.z = 0.0F;
newRot = Quaternion.Slerp(newRot, rotPlayer, Time.deltaTime *speedLookAt);
}
if (vecAxisRef.magnitude != 1) vecAxisRef.Normalize();
newPos.y = 0f;
transform.position = newPos;
transform.rotation= newRot;
}
}
Hard to see what you're asking. You already have Quaternion.LookRotation
, which turns a Vector into an angle. The opposite is Q*Vector.forward
, which gives a Vector aimed in angle Q.
do you know how can i make the player position follow the rotation of the ray?
Answer by MarceloCosta_GamesBR · Jun 11, 2015 at 07:49 PM
see this video and see what i am wanting do i want to align X axis, and Z axis of the player position in direction of the quaternion of green ray... link text