0 votes

I'm currently working on an FPS using Godot 3D based on this tutorial series and wanted to know how to make my character dash forward, backwards and to the sides, all based on where he is currently aiming. I'm kinda new to the engine so code examples would be really appreciated.

asked Dec 7, 2019 in Engine by Moot Point (16 points)

1 Answer

+1 vote

I think there are 2 challenges for this mechanic:

  1. Getting the direction to dash based on aim & user input
  2. Adding some large impulse to the character so that they move in that direction

I assume that your player already has these two variables: a Vector3 for velocity and a Camera that references the Player's camera. To get the direction, you will need the basis from the Camera's global transform.

#Get the rotation of the head
 var aim = camera.get_global_transform().basis;

"aim" has three variables named x, y, and z. These are all Vectors that point up, sideways, and forwards relative to the camera's transform. You can multiply these Vectors with another variable that represents the impulse you want to apply when the player dashes.

var dash_direction = Vector3();
dash_direction += aim.z * Vinput; #Vertical input (ranges from 1 to -1)
dash_direction += aim.x * Hinput; #Horizontal input (ranges from 1 to -1)
dash_direction = dash_direction.normalized();
var dash_vector = dash_direction * dash_speed;

Then add "dash_vector" to your velocity

velocity += dash_vector;
answered Dec 7, 2019 by Phischermen (20 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.