Cube rolling problem (rotation problem)
Hi, I want to make a rolling cube around its edges, it kinda works, it gives the illusion it rolls well.
Here's a gif :
https://gyazo.com/c58e1284c145d1b8144198a15a681629
But the thing is, when it gets colored, I can see it's not rolling as well as I thought. It's like it is rotating around to axis at the same time.
Another gif :
https://gyazo.com/77612aaef950a2bc3392b66d582a93b0
Here is the roll function.
IEnumerator Roll (Vector3 direction)
{
input = false;
float rollDecimal = 0;
float rollAngle = 90;
float oldAngle = 0;
float halfWidth = transform.localScale.x /2;
Vector3 rollAxis = Vector3.Cross(Vector3.up, direction);
Vector3 pointAround = transform.position + (Vector3.down * halfWidth) + (direction * halfWidth);
Quaternion rotation = transform.rotation;
Quaternion endRotation = rotation * Quaternion.Euler(rollAxis * rollAngle);
Vector3 endPosition = transform.position + direction;
while (rollDecimal < speed)
{
yield return new WaitForEndOfFrame();
rollDecimal += Time.deltaTime;
float newAngle = (rollDecimal / speed) * rollAngle;
float rotateThrough = newAngle - oldAngle;
oldAngle = newAngle;
transform.RotateAround(pointAround, rollAxis, rotateThrough);
}
transform.position = endPosition;
transform.rotation = endRotation;
input = true;
}
Thanks in advance,
Answer by LucasP8 · Dec 11, 2019 at 07:37 PM
I found a solution!!
Here is a vid showing what it looks like :
https://www.youtube.com/watch?v=la20yXamV_c
And here his the thread with the solution :
https://forum.unity.com/threads/cube-walking.450347/#post-2915697
A massive thanks to ericbegue who gave the solution.
Your answer
Follow this Question
Related Questions
Roll cuboid does not work properly 1 Answer
How do I stop my cube from rotating when it hits the ground ? 0 Answers
How to ignore a value while animating 0 Answers
Hi, got a problem with my vertical axis. 0 Answers
How to make a cube tumble to player 0 Answers