because not only will it allow me to achieve my goal, but also allow for me to make more complex paths I guess. The reason I thought about paths was because it might solve the problem I’m having where the object bounces since the collisions I have aren’t calculated perfectly.
I guess let’s just go back to the original question, since the path solution was just an idea that won’t work.
Yeah, you gotta walk first before you can run.
If it matters, I’m moving my object with impulses so it can collide with the player when the object can’t move further.
Do you know of a way to solve the discrepancy of collisions that should be touching at the same time on opposite sides?
Character body should be able to handle it.
The safe margin? That should work, just now it doesn’t take the impulse. I’m using the apply_central_force method to move it, is there an equivalent to it for character bodies?
No, you move the character body by script. Doing it with forces is too indirect for this type of movement.
Let the pushed object be character body. Check for overlap returned by get_last_slide_collision() in player and move the pushed object for that amount as well. Move it via its move_and_slide() if you want it to stop at further obstacles. Otherwise you can just manually update its position.
It’s detecting it, however I’m having trouble filtering for only the player, and not the bounding collisions. In fact with them it doesn’t even detecting the player is touching it
Turns out it pushes it, its just very very small. All I need to do now is amplify how much it moves. And thats with the only thing it does is move_and_slide()
Oh thanks! Moving it makes it a little jittery but I think I just need to lerp it.
Well not all of the time. I tested it twice with no changes and it didn’t the first time, but did the second.
I don’t see any jitter. If your frame rate differs from physics tick rate enable physics interpolation in project settings.
Did it and the jitter is reduced but still noticeable.
Post your code. And your character body properties for both bodies
I realize I’m late to this party, but the way I handle stuff like this is with a RigidBody2D and a separate physics mask. No code needed, and you just add the pushable’s physics layer to the tiles around the path the object can take, and you’re done. At least if you’re doing a puzzle like in the Undertale video.
1 Like
Speed is usually 160, or 320 if I’m running
var input_vector = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
velocity = input_vector * speed
move_and_slide()
#Pushable Collision
var collision: KinematicCollision2D = get_last_slide_collision()
if collision:
var collider = collision.get_collider()
if collider.name == "Rock":
var overlap := collision.get_remainder()
if abs(overlap.x) > abs(overlap.y):
collider.velocity = Vector2(overlap.x, 0) / dt
else:
collider.velocity = Vector2(0, overlap.y) / dt
collider.move_and_slide()
Character’s
Pushable’s
How would I make a physics mask? If this work this might be easier to work with lol.
Oh wait I do know, but then how would I limit it to the layer I need? Would it be the section it can move in or can’t move in?
Earlier I tried this by making a hollow cube that acts as a bounding box and that’s what started this, since the object could wiggle up and down slightly, even if they should be touching.
1 Like
Not sure that pushing like this is doable without any code.
Assuming your using a TileMapLayer:
- Rename a Physics Layer “Pusahable”. (For the sake of this I’m going to assume Physics Layer 5.)
- Create a RigidBody2D.
- Turn off Collision Layer 1 and Collision Mask 1.
- Turn on Collision Layer 5 and Collision Mask 5.
- Edit the Tileset in your TileMapLayer.
- Add a Physics Layer.
- Turn off Collision Layer 1 and Collision Mask 1.
- Turn on Collision Layer 5 only.
- In the TileSet, paint the new Physics Layer onto whatever tiles you don’t want the pushable object to be able to move on.
- Place tiles that don’t have that layer to make a track to follow.
- Place tiles around it that do have the layer.
- The player will only be able to move the object along the track.
Oh ye of little faith.