- Home /
Lerp rotation 90 degrees on jump
I simply wish to rotate the player character 90 degrees forward (-90 on the z) with every jump. The player character is a square, I'm trying to emulate the geometry dash style where it lands on the front facing face every jump after a little rotation. Transform.rotation isn't working at all it seems. I have tried euler angles, which was the closest solution, but it wouldn't always rotate exactly 90 degrees. I've learned I cannot read euler angles consistently, but neither quaternions nor simply influencing the rotation seems to be working. Here is the code. It seems like it should be a super simple thing to achieve, what am I doing wrong?? Everything commented out are solutions I have attempted to no avail. The current rotation variable I have shifted between vector 3 and a quaternion depending on what I've been trying. I'm probably just a fool, but please help me solve this. The last ground check incrementing if statement changes the ground check transform to the next face to accurately see if the square is grounded.
void Update()
{
currentMoveSpeed += moveSpeedIncreaseModifier;
grounded = Physics2D.OverlapCircle(groundedCheck[groundedCheckNumber].position, groundRadius, groundLayer);
if (grounded)
{
jumping = false;
}
if (jumping)
{
transform.rotation = Quaternion.RotateTowards(currentRotation, new Quaternion(transform.rotation.x,transform.rotation.y,currentRotation.z -90f,1) , Time.deltaTime * rotationSpeed);
//transform.eulerAngles = Vector3.Lerp(transform.eulerAngles,currentRotation, Time.deltaTime * rotationSpeed);
//transform.rotation = Quaternion.Lerp(currentRotation, new Quaternion(transform.rotation.x, transform.rotation.y, currentRotation.z - 90f, 1), Time.deltaTime * rotationSpeed);
}
myRB.velocity = new Vector2(currentMoveSpeed, myRB.velocity.y);
if(Input.GetKeyDown(KeyCode.Space) && grounded)
{
currentRotation = transform.rotation;
jumping = true;
myRB.velocity = new Vector2 (myRB.velocity.x, jumpForce);
//transform.rotation = Quaternion.Lerp(transform.rotation, new Quaternion(transform.rotation.x, transform.rotation.y, transform.rotation.z - 90f, 1), Time.deltaTime * rotationSpeed);
//transform.RotateAround(transform.position, transform.up, new Vector3(0f,0f,90f));
//Vector3 rotate90 = new Vector3(transform.rotation.x, transform.rotation.y, transform.rotation.z + 90f);
//transform.eulerAngles = Vector3.Lerp(transform.rotation.eulerAngles destination,Time.deltaTime);
if (groundedCheckNumber == 3)
{
groundedCheckNumber = 0;
} else
{
groundedCheckNumber++;
}
}
}
Your answer
Follow this Question
Related Questions
Pinball Flipper using Quaternion.Lerp? 1 Answer
how do i use Quaternion lerp on only the Y and Z axis 0 Answers
Smoothly Rotate 2D sprite 90 degrees on click 2 Answers
Lerping Quaternions Results in NaN's 1 Answer
Use Lerp to rotate object 2 Answers