I use click to move, but don't want my player to rotate... How to fix this rotation?
I'm making my first game in unity. What I trying to achieve is letting a player move by clicking somewhere in the room. (this works!). But to look around, I use a drag screen to look script (also works).
The only problem I have at this moment is: my player is rotating when I'm clicking somewhere in the room to move the player. How can I stop this rotation?
This is my click to move script, I think I have to normalize something but don't know how...
public LayerMask whatCanBeClickedOn;
private NavMeshAgent myAgent;
private void Start()
{
myAgent = GetComponent <NavMeshAgent>();
}
private void Update()
{
if (Input.GetMouseButtonDown (0))
{
Ray myRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(myRay, out hitInfo, 100, whatCanBeClickedOn))
{
myAgent.SetDestination (hitInfo.point);
}
}
}
Answer by Pie556 · Sep 11, 2021 at 12:02 AM
Well so if im not wrong then your player is rotating when you dont want it to rotate, since i am not 100% sure what the problem is then i and going to give you are a solution that may or may not work Also if you use my solution then your player will not be able to rotate the whole game So all you need to so is go to your rigid body and go to constraints and freeze all the rotation just check all of the boxes that are near the rotation area, if you are making 2D game just check the Z axis and yeah but it will stop rotation for the player and your player wont be able to rotate in the game. Hope this help! if not then sorry i could not userstand fully what you were trying to say!
Your answer
Follow this Question
Related Questions
Best way to make player Parallel to walls? 1 Answer
Restricting player camera rotation.x 0 Answers
My player character rotates in place. Help much appreciated! 2 Answers
Restrict second touch 0 Answers