1
\$\begingroup\$

My goal here is simple. I am making a top down shooter kind of game, and I want the player to simply rotate in one axis, towards where the mouse is on the screen. I got it working, but it rotates so fast that everything is out of control. The following method is called in Update() on my player's game object

void RotatePlayer()
{

    var targetPosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 100);

    targetPosition = Camera.main.ScreenToWorldPoint(targetPosition);

    targetPosition.y = transform.position.y * Time.deltaTime;

    transform.LookAt(targetPosition);

}

That rotates in the direction of the mouse, but like I said it rotates so fast that you cannot control it.

As you can see I tried to multiply by delta time, but that did not seem to do anything. Also, changing that last parameter of "100" to a lower number also does not do anything.

Any help is greatly appreciated.

\$\endgroup\$
1
\$\begingroup\$

I have found another way to do this,

void RotatePlayer()
{               
    var xDeg = Input.GetAxis("Mouse X") * m_TurnSpeed;

    transform.Rotate(0f, xDeg, 0.0f);
}
\$\endgroup\$
0
\$\begingroup\$

Add a float rotateSpeed variable from 0.00f to 1.00f and multiple your targetPosition.y by that after Time.deltaTime.

I can't test this right this very moment, but I'm fairly certain that should work.

\$\endgroup\$
  • 1
    \$\begingroup\$ That still did not work, but I did find another way to accomplish what I was trying to do. code void RotatePlayer() { var xDeg = Input.GetAxis("Mouse X") * m_TurnSpeed; transform.Rotate(0f, xDeg, 0.0f); } \$\endgroup\$ – BenjaFriend Jun 28 '16 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.