Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Simulating joystick axis to move towards an object

Discussion in 'Scripting' started by unfungmz, Nov 23, 2019.

  1. unfungmz

    unfungmz

    Joined:
    Jul 29, 2017
    Posts:
    162
    I have a third person charactercontroller set up (FPS/over the shoulder view). I can move around just fine, but there's times when I want to move my character to a specific vector that's out of my control. I'd basically need to make sure he moves at the max speed as if I was pressing on the joystick, but I'm not sure how I'd do that. Here's how I'm doing my movement:

    MyMove = CameraLookAt.transform.forward * Left_Vertical;
    MyMove = MyMove + CameraLookAt.transform.right * Left_Horizontal;
    MyMove.y = MyMove.y + (Physics.gravity.y * 1.0f);
    controller.Move(MyMove * Time.deltaTime);

    I'm basing the angle of my move on the camera's position (behind the character), that way I can move in any direction regardless of the rotation of the camera. eg: pressing up will always move me directly away from the camera

    so I'm wondering how I could move towards a specific vector as if I was using the left thumbstick
     
unityunity