- Home /
Can you detect the movement of the left and right How can it?
Sorry for my poor English.
Already, I have to move freely in the virtual keyboard players.
I'm locked on in "transform.LookAt(enemy);", Targetting..
var enemy : Transform ;
function FixedUpdate () {
transform.LookAt(enemy);
In this state, I want to detect if the player is moved to the left or right, or has moved to either.
However, as the image is an overhead view.
The reason for this is if you move to the left, because you want to assign in the "mecanim" individual animations that are walking to the left.
How do you do it can be detected?
.
I is likely to be used to go etc., "Vector3.Dot" try a few times, I'm not sure.
(in the) function FixedUpdate () {
newpos = thisTransform.forward;
var Dot = Vector3.Dot(newpos,prevpos);
Debug.Log("Dot =" + Dot);
prevpos = thisTransform.forward;
Answer by robertbu · Feb 28, 2013 at 09:34 PM
Take a look at SignedDotProduct() method in the Math3D script. I've never used it, but here is the comment with the method:
//This function calculates a signed (+ or - sign instead of being ambiguous) dot product. It is basically used
//to figure out whether a vector is positioned to the left or right of another vector. The way this is done is
//by calculating a vector perpendicular to one of the vectors and using that as a reference. This is because
//the result of a dot product only has signed information when an angle is transitioning between more or less
//then 90 degrees.
Thanks for the answer! I was able to resolve the following.
private var prevpos : Vector3 ;
private var newpos : Vector3 ;
//in the Update()...
// Animator Left or Right Judge and Input
if ( name == $$anonymous$$amaeSuriashi )
{
// Dot
newpos = thisTransform.forward;
var Dot = Vector3.Dot(newpos.normalized,prevpos.normalized);
//if (Dot <= 0.9999 )
var Cross = Vector3.Cross(newpos,prevpos);
//else
// Cross.y = 0;
anim.SetFloat("Direction",Cross.normalized.y);
//Debug.Log("Cross = " + Cross.normalized.y);
}
function LateUpdate ()
{
prevpos = thisTransform.forward;
}
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Script working for standard FPS controller not mobile FPS controller 1 Answer
LookAt not working, points in wrong direction. 1 Answer
Performance Question on Kinematic Rigidbodies 1 Answer
How use Streaming Assets and Handheld.PlayFullScreenMovie iOS? 1 Answer