Pushing problem

Godot Version



I have made a game where you can push cubes. As you can see in the video the cube just gets stuck sometimes for no reason. The surface is completely flat. Its just a tile map surface. Can someone please help me with this?

Maybe try changing the collision? Might be possible that you made a minimal mistake with the collision shapes and now the cube gets stuck.
It’s a square after all, so it should be really sensible to these little differences.
Other that that I wouldn’t know what to do either.

Just made sure, and it is a Rectangle CollisionShape2D that stretches from corner to corner and exactly matches the cubes outline. I also just tried some other Shapes and stuff but it still gets randomly stuck.

Also just to anyone who might reply. I tried to also add a different cube and still the same result

Tough one…
Could you maybe add some code here? Or the editors properties? Maybe thats were the problem is

1 Like

I mean if it was something that isn’t random I could probably solve it with some code. But since I don’t know the issue and it is completely random I can’t solve it with code.

What do you mean by editor properties?

Try change value Safe Margin in CollisionShape2D.

Well, the editor properties are on the right side of the godot UI. You can change properties like mass, scale and position. Maybe you accidentally changed something important in the editor that affects the physics too much

Just spent some hours wrestling with pushing cubes around.

Assuming you use a player character to push a RigidBody2D?

They tend to dig themselves every so slightly in with a corner when pushing due to a very slight rotation. And if you turn of the rotation on the cube they tend to slide like on ice or just fly off.

I got it working by putting this code on the player:

var push_force = 80.0

	# move colliding rigidbody - after calling move_and_slide()
	for i in parent.get_slide_collision_count():
		var c = parent.get_slide_collision(i)
		if c.get_collider() is RigidBody2D:
			c.get_collider().apply_central_impulse(-c.get_normal() * push_force)

In the cube’s script I give it friction this negates the flying off of the cube when you have rotation on:

	if linear_velocity.x != 0:
		linear_velocity.x = move_toward(linear_velocity.x, 0, 1500 * delta)

The cube is on it’s own layer and doesn’t mask the player. The player does mask the cube. I have turned the rotation off on the cube cause I don’t want the player to be able to rotate them by pushing, if I push it off a cliff I can turn it on again by adding:

if linear_velocity.y < 0:
lock_rotation = false

I use a mass of 3KG for the cube and a push force of 80 on the player. Upping or lowering the push force has the visual effect of lowering or raising the weight of the cube.

1 Like

Hey thanks for the reply.

I have everything the same as you said. Even the code is exactly the same. But it still gets stuck randomly. The link you have sent doesn’t seem to work (atleast for me).

Do you think this could be a problem with the tile map? I have checked if there are no gaps in the blocks for the tile map and there aren’t any, but maybe there is a setting I am missing?

The link is just a video of my player pushing a block.

Could be that it get’s hung up on the tile map. To test that you can put an area2d with a large collision map as a floor in your scene. If that works like it should it must be the tile map with mutliple collision shapes as floor.

1 Like

Just changed the floor to an Area2D with a CollisionShape2D and stretched it over the floor. It works now. I have no clue as to why the tilemap makes it get randomly stuck though.

Thank you for solving my problem!

1 Like

I think it has to do with a tile map floor being made up of a lot of collision shapes in a row, and somehow it gets stuk at one of the edges.

1 Like

Yeah that could maybe be the reason. Now just to make a pick up and throw system… Hopefully I won’t be bothering anyone with that again :sweat_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.