• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by guccipf · Aug 13, 2019 at 03:21 PM · 3dgetaxis

How Can I Move My Player With Camera Direction And Without Using Get Axis??

hello people i hope y'all doing fine, i know that the title wasn't that obvious but basically i want to move my fps player to the direction that the camera is facing for example when i press the W key the player should move forward acording to the direction he's looking at, how ever thats not the problem here i managed to find a solution after all, but the problem is as you can see in the code im using get axis which mean the movement keys are by default ARROWS and WASD and i want to change the keys To what ever i want without having to go to project setting and change get axis settings, so i tried to use GET KEY and it does not work what can i do to make it work?? again im sorry if the question is not that obvious and here is the code im using :

 public float movespeed;
 public Transform tr;
 public Rigidbody rb;
 public CharacterController charactercontroll;

 public float rotation_speed;
 private float mousex;

 
 void Update()
 {
     

     mousex += Input.GetAxis("Mouse X") * Time.deltaTime * rotation_speed;
     
     tr.rotation = Quaternion.Euler(0, mousex, 0);


     
     //////////////////CHANGE THE GET AXIS WITH GET KEY SOMEHOW 

     float horizontalmove = Input.GetAxis("Horizontal") * Time.deltaTime * movespeed;
     float verticalmove = Input.GetAxis("Vertical") * Time.deltaTime * movespeed;

     Vector3 updown = transform.forward * verticalmove;
     Vector3 rightleft = transform.right * horizontalmove;



     charactercontroll.SimpleMove(updown + rightleft);
     
 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by JonPQ · Aug 13, 2019 at 04:12 PM

something like this....

  if (input.GetKeyPressed(keycode.W))
     {
      move forward...     // dont forget to set forward vector .y to 0 if you are walking on a flat surface.
     }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

136 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Same Collision Rebound Force on Cars 0 Answers

Camera Keeps Following Mouse in Pause Menu 0 Answers

Want to make GameObject follow another GameObject's path Unity3D 1 Answer

Update Renderer Bounding Volumes - Lower Game Performance 1 Answer

2D object look at 3D object 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges