- Home /
Rotate the player toward a direction
Maybe there's a similar question out there but I can't find it. I want my fps character to be turned toward a specific direction. The problem is that every code I've found that seems to do that always resets my character to the original rotation.
For example I have a teleporter that teleports the character to another room. After the teleportation I want him to face a certain direction. But he's just turned a single frame and then turns back to the direction he was looking in when stepping into the first teleporter.
I'm just using a function like this and it seems to work that one frame but then just reverts back.
function Teleport()
{
this.transform.rotation.y = 0.1;
}
I also have no clue why the degrees don't match the number after the "y =" but that's not the main issue.
Thanks.
Is something overriding the player's rotation?
This code looks like it should work, so perhaps the problem is elsewhere?
Hm, that might be the issue. I tried to turn a table using the same code now and that seems to rotate it permanently. I can't seem to find the reason for why it won't work on the FPS controller though.
It's possible that in the controller it's using a specific value that is kept to define which direction the player is looking, so after you manually set it once, it still has the turn value and sets it back?
Seems to be the case. I'll have to look into that. Thanks for the tip.