- Home /
Question by
constantlime830 · Jul 20, 2020 at 10:04 AM ·
scripting problemconfused
SMOOTH ROTATE ON JUMP?????????,Smooth Rotation On Jump?????????
hello, i am Quite new to unity and i want to make my character rotate smoothly when i pres space. currently my script rotates the player but instantly, here it is;
using System.Collections.Generic; using System.Threading; using UnityEngine;
public class JumpRotate : MonoBehaviour { [Tooltip("The Rotation Of The Object")] public float rotation = 90f; [Tooltip("The Speed Of The Rotation(WIP)")] public float SpeedOfRotation = 10f; private bool IsJumping = false;
public void Update()
{
// Will Activate On KeyPress
if (Input.GetKeyDown("space"))
{
IsJumping = true;
transform.Rotate(0, 0, rotation);
}
}
}
Comment
Answer by ilagef · Jul 20, 2020 at 11:45 AM
Try to use Transform.RotateAround
Like this:
[Serializefield] public float rotateSpeed = 10f;
public void Update()
{
// Will Activate On KeyPress
if (Input.GetKeyDown("space"))
{
IsJumping = true;
Vector3 direction = Vector3.up; // change this to the desired direction
transform.RotateAround(transform.position, direction, rotateSpeed * Time.deltaTime);
}
}