- Home /
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);
}
}
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.
}
Your answer
Follow this Question
Related Questions
Is Unity3D capable of handling a MMo 3 Answers
Error downloading Unity 2 Answers
How to use costum device like 3dsensor in unity 1 Answer
Drag Object Via Axis Handles 0 Answers