Sunday, September 16, 2018

unity - Help with character turning?


I'm simply trying to make my character turn in his place, whether he's standing still or moving, currently, he isn't turning what-so-ever. Here is the code that I currently have for turning:


I AM NO LONGER USING THIS TURNING FUNTION vvv


void Turning()
{
Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit floorHit;


if (Physics.Raycast (camRay, out floorHit, camRayLength, floorMask))
{
Vector3 playerToMouse = floorHit.point - transform.position;
playerToMouse.y = 0f;

Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
playerRigidbody.MoveRotation(newRotation);
}
}


So what should be happening is my character should turn and face toward wherever my mouse is pointing, but that isn't happening and I'm not sure why.


Thank you in advance for any assistance.




WHAT I AM USING NOW


I have alternatively tried another bit of code which I will post below, I completely got rid of what is above in place of this:


Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
transform.LookAt(mousePos);

This will actually make the camera follow the mouse, but it goes crazy, the camera seems to spin in circles rapidly : here is actually a gif of what is happening. https://gyazo.com/952da6c28e644b7b0e6500a597b6804e/preview Could anyone help me figure how how to fix it?





No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...