Help understanding how to push and pull object

The post above shows the full script for the box. The player is just the basic one that godot provides.

image

Thats a pic of the running game. When the box is set to the player mask it moves the box by the player running into it.

I don’t see any unnatural things, it’s pretty good now.

Yeah it moves but i want it to move only when i have the key pressed.

Do you mean the box shouldn’t be pushed by the player, but moved by the code above, and only when the action key is pressed?

1 Like

When the player is in the red box and i hold the key down, that is when the player can push the box.

1 Like

Then the code above will do since it is looking at the action key.

This is what i mean, it doesnt move the box. I cant understand why it wont move it when the button is pressed down.

Here is an out to show the button and direction pressed while within the red box.

image

And I think there would be better choices to achieve this. Like disabling the physics temporarily for changing position directly, then resetting it back.

I just created a test scene with the box code, the player might not be set in the “Player” group, so the action_push_ready will never be true.

In my scene, I raised the force, and it worked as expected. Your right-handle area mask might not have added the player layer, or you might disabled the monitoring property.

I have the player node in a group called “Player”. So that checks.

Monitoring is set to on.

mask for the Righthandle is set to player also.

Box is not set to player mask or layer.

Still no dice for me. Does your rigidbody have the player set on the layer and mask?

Yes, but that doesn’t matter, for your setting is correct, try to use apply_impulse() instead of apply_force() with at least 3000 force.

1 Like

I think i have an issue with key held down. If i press “O” it jumps fine.

if Input.is_action_just_pressed("Debug_Action"):
		apply_force(Vector2(0,-10000))
		pass
	elif Input.is_action_pressed("Debug_Action"):
		action_hold_time += delta
		print("hold down key: ", action_hold_time)
		if action_hold_time >= HOLD_ACTION_THRESHOLD:
			apply_force(Vector2(0,-10000))
			pass

Debug_action key = “O”
image

Player_action key = left mouse button and “E”
LMB
image
E
image

Not sure why “O” is not reaching higher values.

erm that worked!

1 Like

Okay. These are now set.

const IMPULSE_STRENGTH: float = 1500.00 
apply_impulse(force)

This slowly moves the box, however, the player will pass through it. I believe this is because the player is moving faster than the force.

Edit:

Ah okay I have tested setting the Rigidbody to the player mask and the boxmoves when the player walks into it so thats out.

Edit2:

Okay I just made another box with rigidbody - sprite and collision box. I set the mask to the player on this box and the player can walk into it and move it… There is something screwy going on with the player here. <---- this is incorrect as i just setup a simple project with player and box and the player pushes it.