- Home /
Question by
vicar_vahnce · Oct 05, 2018 at 01:28 PM ·
script.player movementgame development
I need to turn my player 90 degrees on mouse click but wanted the turn to be slower while moving along the immediate direction it faces
hello everyone,
I am making a game in which the player is constantly charging towards the direction it is facing.
It turns 90 degree on every mouse click.
The problem is it snaps to that direction instead of slowly turning while having velocity towards the direction it is facing at that moment ( kind of like how we turn while running in real life ).
This is the code i am using :
public class playerScript : MonoBehaviour {
public float speed;
private Vector3 dir;
CharacterController controller;
Animator anim;
// Use this for initialization
void Start()
{
dir = Vector3.zero;
controller = GetComponent<CharacterController>();
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update() {
if (controller.isGrounded)
{
if (Input.GetMouseButtonDown(0))
{
anim.SetInteger("condition", 1);
if (dir == Vector3.forward)
{
dir = Vector3.left;
transform.eulerAngles = new Vector3(0, -90, 0);
}
else
{
dir = Vector3.forward;
transform.eulerAngles = new Vector3(0, 0, 0);
}
}
}
float amountToMove = speed * Time.deltaTime;
controller.Move(dir * amountToMove);
} }
I need ideas to implement this functionality.
Any help appreciated.
Much regards,
Cheers.
Comment
Your answer