Ship Movement dampened?
Asked Answered
S

2

0

Hello!

I have a ship that I'm reworking the movement on and have attached the relevant script below. My thrust variable acts like my speed and I've set it to 800. when I run, the velocity print statements for the 'left, right, up' directions max at 368 and my 'down' direction maxes at 775. The ship is a RigidBody2D and I'm sure I'm missing something simple about the physics. All my damp values and gravity scale is set to 0.

func _physics_process(delta):
	mouse_pos = get_global_mouse_position()
	var direction = mouse_pos - position
	var mouse_angle = direction.angle()
	var cur_vertical_velocity = get_linear_velocity().y
	var cur_horizontal_velocity = get_linear_velocity().x
	global_rotation = lerp_angle(global_rotation, mouse_angle, angular_speed)
	
	if Input.is_action_pressed("move_right"):
		set_linear_velocity(lerp(linear_velocity, Vector2(thrust, cur_vertical_velocity), 0.05))
		
		print(linear_velocity)
	if Input.is_action_pressed("move_left"):
		set_linear_velocity(lerp(linear_velocity, Vector2(-thrust, cur_vertical_velocity), 0.05))
		
		print(linear_velocity)
	if Input.is_action_pressed("move_up"):
		set_linear_velocity(lerp(linear_velocity, Vector2(cur_horizontal_velocity, -thrust), 0.05))
		
		print(linear_velocity)
	if Input.is_action_pressed("move_down"):
		set_linear_velocity(lerp(linear_velocity, Vector2(cur_horizontal_velocity, thrust), 0.05))
		
		print(linear_velocity)
	else:
		set_linear_velocity(lerp(linear_velocity, Vector2.ZERO, 0.06))
		
	position = position.clamp(Vector2.ZERO + start_pos, ship_boundaries)

Thanks

Shod answered 22/11, 2023 at 17:57 Comment(0)
P
1

Shod the move_down else is messing up the velocity when you don’t press it.

Play answered 22/11, 2023 at 20:49 Comment(0)
S
0

Play
derp thanks haha

fixed it by changing the else to elif:

elif Input.is_anything_pressed() == false:
		set_linear_velocity(lerp(linear_velocity, Vector2.ZERO, 0.06))
Shod answered 22/11, 2023 at 20:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.