Platypus: sprite/spine disappearing on ground contact (SOLVED)

Hi,

I’m trying to use platypus to work around the problem described in Directional platforms help.

I’m making an infinite runner type of game based on the “runner” example (https://defold.com/assets/endlessrunner/).

I drop my hero inside the level, so it starts “falling” and lands on the ground. But shortly after it lands, the hero sprite or spine (I tried both) disappears. With “debug = true”, the debug rays also disappear.

Here’s my hero.script:

local platypus = require "platypus.platypus"

function init(self)
	msg.post(".", "acquire_input_focus")

	self.platypus = platypus.create({
		collisions = {
			separation = platypus.SEPARATION_RAYS,
			groups = {
				[hash("geometry")] = platypus.DIR_ALL,
			},
			left = 40, right = 40, top = 40, bottom = 40,
		},
		gravity = -800,
		max_velocity = 300,
		allow_double_jump = false,
		allow_wall_jump = false,
		allow_wall_slide = true,
		wall_slide_gravity = -3000,
		debug = true,
	})
end

function update(self, dt)
	self.platypus.right(600)

	self.platypus.update(dt)
end

function on_message(self, message_id, message, sender)
	self.platypus.on_message(message_id, message, sender)
end

The hero is automatically moving to the right at 600 pixels/s.
The ground (collision group “geometry”) is moving at 600 pixels/s to the left. So the hero is “running” in place, which is what I want it to do.

Both hero and ground collision is set to “kinematic”.

When I turn on physics debug, i can still see the heros collision shapes and everything else works as expected.

The hero does not disappear if I change ground collisions to “static”. But setting it to that is not useful, as I want the ground to move.

I wonder if your collision resolving might have a bug in it, and accidentally moves the character instantaneously to another place?
This could for example happen if you get NaN's in the calculations.

What if you print out the hero’s position each frame, does it seem correct?

To maybe elaborate a bit further:

The ground is “kinematic” because I wanted to implement something like pits the hero can fall into and die.

My game is very close to the runner example. The example does the ground with a “static” collision type (https://defold.com/tutorials/runner/#step-6---ground-physics-and-platforms), which does not have the problem described in Directional platforms help, but I wasn’t able to implement pits with “static”.

Now with the ground changed to “kinematic”, I run into the aforementioned “directional platforms help” problem, which I’m trying to fix with Platypus…

The hero seems to disappears as soon as it touches a new ground game object.

Printing out the heros position, the X position seems to reset to -6.666 every time the hero touches a new ground game object. Which is weird… because the collision shape i see with physics debug enabled doesn’t move at all.

The heros Z position is subtracted by 0.666 every time the hero touches a new ground game object. Which would definitely explain the disappearance of the sprite, as it moved behind my background image.

Hmm.

I’m not sure what to make of this. I’m not setting Z anywhere and neither is platypus.

To accommodate for horizontally moving platforms and things like that Platypus will change parent of the player to anything it lands on and I’m guessing this is what causes the problem. I’d like to investigate this and see what can be done to solve your particular case. Could you please share your project with me (bjorn@defold.se) (exclude .git and build folders to reduce zip size)?

I’ve never used/looked at Platypus, but would it maybe be better to have a “parent” for the purposes mentioned, that is a parent in name only to avoid this type of issue? As in, not actually parent the GO to the object, but have some kind of self.parent property instead, that if ~= nil (because its group is “moving_platform” or whatever) has a function for tracking that “parent”'s position and applying it to the GO?

Generally speaking, a moving platform would be a lot less common than a static platform. Personally I would probably treat it as a specific case, instead of directly GO parenting the character to everything it touches just in case it’s a moving platform (again, haven’t seen the code).

I experimented with this but since the game object transform is updated after the update function there’s a one frame delay in capturing the movement of the moving platform which will cause the player to drift a tiny bit while the platform is moving.

@marco Thank you for sharing the project. The reparenting is indeed the problem. I have released version 4.1.0 of Platypus where you can pass in reparent = false as a config value to disable reparenting. This will solve your problem. Give it a try and let me know what you think!

Thank you britzl, the problem is solved in 4.1.0.

1 Like