Add a force-push for Rigidbodies #1

Closed
opened 2026-04-27 20:01:57 +00:00 by OddlyTimbot · 1 comment
Owner

When player hits a key, check to see which way they are facing and deliver a force-push to pushable objects:

		var collider = right_cast.get_collider()
		#check if this is okay
		if collider is Node && collider is RigidBody2D && collider.is_in_group("pushable"):
			pushTarget = collider
			pushEnabled = true
			
	if left_cast.is_colliding() && facing==FaceDirection.LEFT:
		var collider = left_cast.get_collider()
		if collider is Node && collider is RigidBody2D && collider.is_in_group("pushable"):
			pushTarget = collider
			pushEnabled = true
		 
	if not right_cast.is_colliding() && not left_cast.is_colliding():
		pushEnabled = false```
When player hits a key, check to see which way they are facing and deliver a force-push to pushable objects: ```if right_cast.is_colliding() && facing==FaceDirection.RIGHT: var collider = right_cast.get_collider() #check if this is okay if collider is Node && collider is RigidBody2D && collider.is_in_group("pushable"): pushTarget = collider pushEnabled = true if left_cast.is_colliding() && facing==FaceDirection.LEFT: var collider = left_cast.get_collider() if collider is Node && collider is RigidBody2D && collider.is_in_group("pushable"): pushTarget = collider pushEnabled = true if not right_cast.is_colliding() && not left_cast.is_colliding(): pushEnabled = false```
OddlyTimbot added reference null 2026-04-27 20:02:42 +00:00
OddlyTimbot removed reference null 2026-04-27 20:02:49 +00:00
Author
Owner

Also map the shove control to deliver the impulse:

if Input.is_action_just_pressed("shove") && pushEnabled:
		print("I want to shove")
		var shoveDirection:int
		match facing:
			FaceDirection.RIGHT:
				shoveDirection = 1
			FaceDirection.LEFT:
				shoveDirection = -1
		current_state = State.SHOVE
		pushTarget.apply_central_impulse(Vector2(shoveDirection,0)*700)
Also map the shove control to deliver the impulse: ``` if Input.is_action_just_pressed("shove") && pushEnabled: print("I want to shove") var shoveDirection:int match facing: FaceDirection.RIGHT: shoveDirection = 1 FaceDirection.LEFT: shoveDirection = -1 current_state = State.SHOVE pushTarget.apply_central_impulse(Vector2(shoveDirection,0)*700) ```
OddlyTimbot added the
enhancement
label 2026-04-27 20:27:36 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: OddlyTimbot/AprilGameExample#1
No description provided.