Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Juan Manuel |
Hi guys, how are you?
Im working on a Flappy Bird clone and I have a problem. When the bird flap I want it to rotate instantly to a 30 degree angle. It does but it last only a fraction of a second and then comes back to its previous angle. How can I archive that? Here is my code
extends RigidBody2D
func _physics_process(delta):
if Input.is_action_just_pressed("ui_jump"):
_flap()
if (linear_velocity.y > 0):
_rotate()
func _flap():
set_angular_velocity(0)
set_rotation(deg2rad(-30))
set_linear_velocity(Vector2(linear_velocity.x, -200))
func _rotate():
set_angular_velocity(3)
See, the physics engine gets fussy if you directly mess with the RigidBody2D in the wrong way.
Look into the _integrate_forces(state)
method that RigidBody2D has.
System_Error | 2020-03-16 16:14