- Home /
Question by
Venividiviciuus · Jun 25, 2021 at 12:15 PM ·
rotationmovementplayerangle
Curve player movement
how can I make my player curve while walking in x wAsD <- AD test my script.. please lift me up..
void Update()
{
float horizontalInput = Input.GetAxisRaw("Horizontal");
float verticalInput = Input.GetAxisRaw("Vertical");
Vector3 movementDirection = new Vector3(horizontalInput, 0, verticalInput);
movementDirection.Normalize();
if(movementDirection != Vector3.zero)
{
float targetRotation = Mathf.Atan2(horizontalInput, verticalInput) * Mathf.Rad2Deg + Camera.main.transform.eulerAngles.y;
transform.eulerAngles = Vector3.up * Mathf.SmoothDampAngle(transform.eulerAngles.y, targetRotation, ref turnSmoothVelocity, turnSmoothTime);
}
float targetSpeed = speed * movementDirection.magnitude;
currentSpeed = Mathf.SmoothDamp(currentSpeed, targetSpeed, ref speedSmoothVelocity, speedSmoothTime);
transform.Translate(transform.forward * currentSpeed * Time.deltaTime, Space.World);
anim_Warrior(movementDirection);
}
Comment
Answer by ravenclarico · Jun 29, 2021 at 04:08 AM
you need to use velocity, make them build up speed slowly so the movement looks clean.