Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How can I solve the question of mouse direction and player move direction in FPS game

Discussion in 'Scripting' started by unity_408540137, Dec 8, 2022.

  1. unity_408540137

    unity_408540137

    Joined:
    Oct 23, 2022
    Posts:
    44
    Recently, I have tried to make a FPS simple game including, player + camera.

    First of all, I make a script for controlling in Mouse.

    and a script for controlling player movement.

    At first, player and camera face the same direction; therefore I use vertical button to controller player.
    But When I turn my mouse to the right direction, even though, Camera and player face the same direction, however, vertical button no longer controlled my player. I have to use horizontal button to control my player to move forward or backward.

    Is that related to TransformDIrection or localRotation?, I am confused by the question.
    By the way, I have searched for many video solving this problems by using rigidbody attribution.
    And I use Character Controller attribution. Does it matter?
    Thanks~
     
  2. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    Best way forward is to show your current code so others can better see what’s wrong here

    the part in particular id want to see is the getkey inputs
     
  3. unity_408540137

    unity_408540137

    Joined:
    Oct 23, 2022
    Posts:
    44
    OK, I use transform.TransformDirection to solve this problem, thanks~