Skip to main content
added 81 characters in body
Source Link
KI.
  • 472
  • 2
  • 6
  • 10

I'm not quite sure what you mean by "ignoring the rotation". However, I'm going to assume this is based off Brackey's FPS movement tutorial, as I have the same code in one of my older projects, and that you are trying to achieve the same thing as the tutorial. In that case, you need to change Vector3 move to

float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;

I'm fairly sure that you can also do this

Vector3 move = transform.right * Input.GetAxis("Horizontal") + transform.forward * Input.GetAxis("Vertical");

and have the code work

The reason your code is not working is because Vector move will move to the player to a world position, which means it will ignore rotation.

By changing the code to this, the direction of the x and z values will be aligned to the player's x and z axis, meaning that if the player rotates, the axis will rotate as well.

I'm far from an experienced programer, but I hope I explained it well enough.

I'm not quite sure what you mean by "ignoring the rotation". However, I'm going to assume this is based off Brackey's FPS movement tutorial, as I have the same code in one of my older projects, and that you are trying to achieve the same thing as the tutorial. In that case, you need to change Vector3 move to

float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;

I'm fairly sure that you can also do this

Vector3 move = transform.right * Input.GetAxis("Horizontal") + transform.forward * Input.GetAxis("Vertical");

and have the code work

The reason your code is not working is because Vector move will move to the player to a world position, which means it will ignore rotation.

By changing the code to this, the direction of the x and z values will be aligned to the player's x and z axis, meaning that if the player rotates, the axis will rotate as well.

I'm not quite sure what you mean by "ignoring the rotation". However, I'm going to assume this is based off Brackey's FPS movement tutorial, as I have the same code in one of my older projects, and that you are trying to achieve the same thing as the tutorial. In that case, you need to change Vector3 move to

float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;

I'm fairly sure that you can also do this

Vector3 move = transform.right * Input.GetAxis("Horizontal") + transform.forward * Input.GetAxis("Vertical");

and have the code work

The reason your code is not working is because Vector move will move to the player to a world position, which means it will ignore rotation.

By changing the code to this, the direction of the x and z values will be aligned to the player's x and z axis, meaning that if the player rotates, the axis will rotate as well.

I'm far from an experienced programer, but I hope I explained it well enough.

Source Link
KI.
  • 472
  • 2
  • 6
  • 10

I'm not quite sure what you mean by "ignoring the rotation". However, I'm going to assume this is based off Brackey's FPS movement tutorial, as I have the same code in one of my older projects, and that you are trying to achieve the same thing as the tutorial. In that case, you need to change Vector3 move to

float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;

I'm fairly sure that you can also do this

Vector3 move = transform.right * Input.GetAxis("Horizontal") + transform.forward * Input.GetAxis("Vertical");

and have the code work

The reason your code is not working is because Vector move will move to the player to a world position, which means it will ignore rotation.

By changing the code to this, the direction of the x and z values will be aligned to the player's x and z axis, meaning that if the player rotates, the axis will rotate as well.