Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | imekon | |
Old Version | Published before Godot 3 was released. |
I’ve created a sample project here:
The script I use to move the ship (like in an asteroids game) wobbles when you hit thrust (up):
extends RigidBody2D
const ROTATE_SPEED = 250
const ACCELERATION = 5
var size
func _ready():
size = get_viewport().get_rect().size
set_fixed_process(true)
func _fixed_process(delta):
if (Input.is_action_pressed("ui_spin_left")):
rotate(deg2rad(delta * ROTATE_SPEED))
if (Input.is_action_pressed("ui_spin_right")):
rotate(-deg2rad(delta * ROTATE_SPEED))
if (Input.is_action_pressed("ui_thrust")):
apply_impulse(get_pos(), Vector2(0, -ACCELERATION).rotated(get_rot()))
var pos = get_pos()
if (pos.x < 0):
pos.x = size.x - 1
if (pos.x > size.x):
pos.x = 1
if (pos.y < 0):
pos.y = size.y - 1
if (pos.y > size.y):
pos.y = 1
set_pos(pos)
I’m guessing it’s my use of apply_impulse?
not understanding much in rigidBody2D but try replacing apply_impulse
with apply_force
or whatever
rustyStriker | 2017-11-03 16:27
add_force is even worse than apply_impulse. The ship goes into a mad spin.
imekon | 2017-11-03 16:47