Dash towards the mouse with vertical force.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Moot Point

I can dash to the four directions relative to the camera, but only horizontally and can’t quite get the verticality right. I want to be able to dash upwards or downwards at an angle.

This is the code for the dash right now:

velocity = dash_direction * DASH_SPEED
dash_direction = dash_direction.normalized()
velocity = velocity.rotated(Vector3(0,1,0), rotation.y)
velocity = move_and_slide(velocity, Vector3.UP)

I think we will need more code. Can you post the whole script maybe? specifically we will need to see where dash_direction is defined.

Millard | 2021-04-05 18:13

dash_direction is not specified and rotated is adding rotation. Do you have a working code example?

clemens.tolboom | 2021-04-05 18:17

If this is a platformer / side-view situation, the problem might be that gravity is messing up with your vertical speed so the dashes don’t feel right. Try disabling / counteracting the effect of gravity while you are dashing.

mirageowl | 2021-04-05 18:34

It’s a 3D FPS game. This is how the dash function gets it’s direction

	DASH:
		dash_direction = direction
		if direction == Vector3.ZERO:
			dash_direction -= head_basis.z

This is what defines direction

direction = Vector3()
head_basis = head.get_global_transform().basis
direction += (int(s) - int(w)) * head_basis.z
direction += (int(d) - int(a)) * head_basis.x

I’m having trouble on where to apply an angle and force to said angle.

Moot Point | 2021-04-07 10:46

Copy pasting here from another comment
It’s a 3D FPS game. This is how the dash function gets it’s direction

	DASH:
		dash_direction = direction
		if direction == Vector3.ZERO:
			dash_direction -= head_basis.z

This is what defines direction

direction = Vector3()
head_basis = head.get_global_transform().basis
direction += (int(s) - int(w)) * head_basis.z
direction += (int(d) - int(a)) * head_basis.x

I’m having trouble on where to apply an angle and force to said angle.

Moot Point | 2021-04-07 10:48

It’s better to add code to the question to get the whole picture. And maybe empty one of your comments :wink: And I miss the mouse code too.

clemens.tolboom | 2021-04-07 13:30

Ah, sorry, here it is.

func _input(event):
if event is InputEventMouseMotion:
	head.rotate_y(deg2rad(-event.relative.x * MOUSE_SENS))
	var x_delta = event.relative.y * MOUSE_SENS
	if camera_rotation + x_delta > -90 and camera_rotation + x_delta < 90:
		camera.rotate_x(deg2rad(-x_delta))
		camera_rotation += x_delta

Moot Point | 2021-04-07 15:07