Circular movement of player

Hi,

I’ve got a shark as player object which I am trying to control using a script, wherein when I press a key, the shark moves in the desired direction along with the animation.

The script works fine except when I use it for turning towards left side in circular motion. However the same doesn’t give the desired movement as in the rotation is either clock wise or anti clock wise in the same circle.

What I am trying to do is when I press key for right side movement, the shark should move towards right side in circular motion from the last position. Here is the script… Would appreciate any help here.

using UnityEngine;
using System.Collections;

public class PredatorSphereScript : MonoBehaviour
{
private float m_moveSpeed = 50.0f;

	void Start()
    {
		
    }
	
	void FixedUpdate ()
{
      		
        if (Input.GetKey("j"))
        {
            moveLeft();
        }
		else if (Input.GetKeyUp("j"))
        {
            moveSlow();
        }
        if (Input.GetKey("l"))
        {
            moveRight();
        }
		else if (Input.GetKeyUp("l"))
        {
            moveSlow();
        }
     }

	
    public void moveLeft()
    {
		 trtransform.Rotate (Vector3.down * Time.deltaTime * -m_moveSpeed);
		{
			animation.CrossFade("SharkLT", 0.2f);
		}
    }

    public void moveRight()
    {
           transform.Rotate (Vector3.down * Time.deltaTime * m_moveSpeed);
		{
			animation.CrossFade("SharkRT", 0.2f);
		}
    }

}

Not sure I understand your question right but it looks strange that you only call “moveSlow()” only whenever you release “j” or “l”.

(Input.GetKeyUp("l"))

Happens only once during one frame at the exact moment you release the key so your shark probably doesn’t move forward much.

If you always want to move forward and turn at the same time with “J” and “L”, do this

void FixedUpdate ()
{
     if (Input.GetKey("j"))
     {
         moveLeft();
     }
     else if (Input.GetKey("l"))
     {
         moveRight();
     }
     
     moveSlow();
}

If you want to move forward and stop to rotate with “J” or “L”, do this

    void FixedUpdate ()
    {
         if (Input.GetKey("j"))
         {
             moveLeft();
         }
         else if (Input.GetKey("l"))
         {
             moveRight();
         }
         else
         {
            moveSlow();
         }
    }