Moving objects with sweep enabled not working if they are touching the floor and gravity enabled

kir1251
Sun, 21 Apr 2024 20:38:16 +0000
Programming & Scripting

I’m trying to implement two elements:

first, a pushable block that, when pushed by the player, moves by a fixed distance over a period of time or until it hits something. It can also fall down when possible.

second, a moving platform that moving between two points. A player can stand atop of it or push a block there so it will move along with the platform. Also, platform should stop and change direction if it hits something on it’s way, including pushable block or another platform.

How I tried to achieve it: for block I enabled physics and gravity, and then constrained rotation. Then on push I’m moving it every frame using AddWorldOffset with sweep enabled.
For platform physics are disabled and I’m also moving it with AddWorldOffet on every frame.

The problem is, when the block stands on the floor, AddWorldOffset not working, as the Sweep returns hit with the floor, even through the block moves horizontally and the floor is directly down there. Moreover, when a block stands on moving platform, the platform itself becomes stuck, reporting collision with that block.

Am I using the sweep wrong? Or I’m missing a checkbox somewhere which would disable touch collisions from blocking sweep when it’s in different direction? Or Sweep shouldn’t be used this way at all?

P. S. There are some ways I found how to bypass this problem, but all of them comes with notable downsides:

replacing AddWorldOffset with a physic force will make everything way less predictable, which I wouldn’t want for my game.

disabling physics and writing my own gravity with AddWorldOffset makes the block not move along with the platform.

not yet tried, but maybe I should replace Sweep in AddWorldOffset with BoxTraceForObjects and then move an object only up to the collision point? This looks promising, but a bit too complex comparing to Sweep.

1 post - 1 participant