Hi , I created simple practice game of moving player. I finished that part.
Next, I just want to move the player based on keyboard arrow keys.
i.e: <- = To turn left side and move
-> = To turn right side and move and down key to turn back side and move
I created code using Quaternion.Slerp But, When I pressed the left key it turns but after I released it again turns to normal direction.
This is my code using Quaternion.Slerp
void Update()
{
PlayerMovement();
float tiltAroundZ = Input.GetAxis("Horizontal") * tiltAngle;
//float tiltAroundX = Input.GetAxis("Vertical") * tiltAngle;
Quaternion target = Quaternion.Euler(0,tiltAroundZ,0);
transform.rotation = Quaternion.Slerp(transform.rotation, target,Time.deltaTime * smooth);
}
void Playermovementangle()
{
float rad= angle * Mathf.Deg2Rad;
float x= Speed * Time.deltaTime * Mathf.Cos(rad);
float y= Speed * Time.deltaTime * Mathf.Sin(rad);
transform.position += new Vector3(x,0, y);
}
What could I do to move the object like previously i said??
Any one post the solution for this>>> Thanks in Advance>>>>
↧