I have a simple script to control player movement:
void MovePlayer(){
if (Input.GetMouseButtonDown(0)) {
target = (Camera.main.ScreenToWorldPoint(Input.mousePosition));
target.z = transform.position.z;
}
transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);
PlayWalkingAnimation();
}
This enabled me to simply click my mouse anywhere on the screen, and the Player will move to that point.
I have four walking animations (NWSE) that i’d like to play depending on the angle the Player is walking in…if that makes sense…
void PlayWalkingAnimation(movementAngle){
//What is movementAngle???
if (movementAngle >= 45 degrees && movementAngle < 135 degrees){
direction = "walking north";
anim.Play (direction);
} else if (movementAngle >= 135 degrees && movementAngle < 225 degrees)){
direction = "walking west";
anim.Play (direction);
} else if (movementAngle >= 225 degrees && movementAngle < 315 degrees){
direction = "walk south";
anim.Play (direction);
} else {
direction = "walking east";
anim.Play (direction);
}
}
I’m not sure how to get the angle I’m moving in, and if there is any math that might be involved.
Also my if-statements might not be spot on, but this is the general idea of what I’m trying to do…