![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | iota17 |
I am trying to check if my player (RigidBody2d) is colliding with any walls to prevent them from jumping. I was looking through some previous posts to see if I could get anything out of that but it didn’t seem to get me much.
Here is the script I have so far:
extends RigidBody2D
var up_delta = 0.0
func _physics_process(delta):
move(delta)
if up_delta > 0:
up_delta += delta
set_bounce(0.3)
set_contact_monitor(true)
contacts_reported = 1
func move(delta):
if Input.is_action_pressed('right'):
apply_central_impulse(Vector2(5, 0))
if Input.is_action_pressed('left'):
apply_central_impulse(Vector2(-5, 0))
if Input.is_action_pressed('up'):
if get_colliding_bodies() != null:
if up_delta > 0.5:
apply_central_impulse(Vector2(0, -1000))
up_delta = 0.1
elif up_delta == 0:
apply_central_impulse(Vector2(0, -1000))
up_delta = 0.1
if Input.is_action_pressed('down'):
apply_central_impulse(Vector2(0, 5))
thx