I’m trying to make an 8-directional movement for my character and I’ve somewhat succeeded.
My problem is that when I press forward button, my character is looking in the direction in which the camera is pointing(as intended), BUT whenever I release the button, it just snaps back to the original position.
When no keys are pressed, you aint slerpin. Or maybe it’s just resetting you to Quaternion.identity somewhere else in your script. You didn’t post anything like that so idk.
What I tried:
Update()
{
if ( you wanna slerp) //and you do
{
doSlerp(newDir);
}
}
doSlerp()
{
//Slerp here
}
Now when you’re no longer pressing keys, it will continue to slerp. At least in my own test it did. If it doesn’t fix yours, I’ll come up with something else for ya.
EDIT:
Per request, here’s a more elaborate explanation. I’m just gonna show you the scripts I used in an old project that I had used slerp to rotate. I never encountered your problem of snapping back, so idk what’s causing it.
That script was great for what I needed. You throw in an angle, and it looks at it! Easy enough.
Here’s how I called it, which is an 8 direction system you are using.
Update()
{
float hor = (Input.GetAxisRaw ("Horizontal"));
float ver = (Input.GetAxisRaw ("Vertical"));
if (hor == 0 && ver == 0) {
return;
}
else if (hor == 1 && ver == 0)
{
FlyTo (90);
}
else if (hor == 1 && ver == 1)
{
FlyTo (45);
}
else if (hor == 0 && ver == 1)
{
FlyTo (0);
}
else if (hor == -1 && ver == 1)
{
FlyTo (315);
}
else if (hor == -1 && ver == 0)
{
FlyTo (270);
}
else if (hor == -1 && ver == -1)
{
FlyTo (225);
}
else if (hor == 0 && ver == -1)
{
FlyTo (180);
}
else if (hor == 1 && ver == -1)
{
FlyTo (135);
}
else
{
Debug.Log("Movement Error");
}
}
Now, that’s a horrible way to call the function, it’s an old project but I know better now. Do what fits your project best.