Wanting to get a character body 2d to act like its been reparented to a moving platform without actually reparenting it, for a moving platform

Godot Version

Replace this line with your Godot version

Question

I am trying to make a character body2d move like its been reparented. only way i figure out so far is either actually reparenting which works great but this doesnt work with the rest of what i have coded and it actually blips the screen when you reparent so it means changing the entire way the camera works.

i have tried getting the velocitry and adding it to the charactersbodys velocity but this just ends up catapulting or not moving the character enough.

one way i did find was to use global transform to lock the character on top of the platform but it doesnt allow the character to move so it looks wierd and is completely unnatural.

below is the code i have used to get platforms velocity, incase there is a problem with that.
this is attatched to the static body 2d in this chain
-Path2d
-pathfollow2d
-staticbody2d

func _ready():
	previous_position = global_position

func _physics_process(delta : float) -> void:
	platform_velocity = (global_position - previous_position) / delta
	previous_position = global_position

this is the code i attempted to use to add the velocity of the character body 2d to the platform 2d

	if current_platform:
		velocity = velocity + current_platform.platform_velocity
 #or 
	if current_platform:
		velocity += current_platform.platform_velocity		
		

current platform is correctly assigned
just looking to be even just pointed in the right direction. :smiley: much appreciated

Hi, does using the built-in floor platform detection not work?

1 Like

I’m unclear as to what you mean by reparented. Could you explain what you are trying to do?

do you mean is_on_floor()? yes that works but it isnt the detection that is the issue is getting the characterbody2d to move with the moving platform.

as in if you reparent a node to another node then its transforms are affected by that nodes transforms. i want the moment the player jumps on the platform for the platforms movement to afect the player. Basically exactly the same how a real life escalator would work, or a lift. you walk on the platform/escalator/lift and then the platform moves and you are dragged along with it. the player is a CharacterBody2D and the platform is a Path2D with a Pathfollow2D as a child and a StaticBody2D as the actual platform following along the path2d

i meant the built in feature to apply a floor’s velocity to a characterbody ontop of it

1 Like

Why doesn’t AnimatableBody work?

Anyway, maybe you can utilize a RemoteTransform for this, though I’m unsure what exactly you’re trying to do… If you just put the platform’s transform on the player, you also need to disable the player’s physics while they’re on the platform, because otherwise they’ll keep falling for example, no? It sounds kind of complicated vs using an AnimatableBody.

StaticBody isn’t meant to be used this way. The way you’re doing it is simply teleporting the platform, and then the player character will find itself suddenly inside the platform and do something unexpected. Maybe. This is my experience doing something similar.

1 Like

I highly recommend you watch this video:

There is a section which specifically shows how to set up rotating platforms.

Change your platform to an AnimatableBody2D. StaticBody is not meant to move; and a CharacterBody2D will automatically apply a moving platform’s velocity under default settings.

im sorry i am unaware of this feature, which one is this?

i will give that a go thankyou

okay i will try with an AnimatableBody and see if that is easier to use

So this seems like its exactly what i need but the “MR G” in this is a child of the Platform 1. I need the MR G to inherit these transforms without being a child of the node.

changing it to an animaterd body 2d crerates rerally unexpected behavior. The player seems to stand on a collision that isnt viewable even by the editor and with veiw collisions on the collision box is moving but does not act as a collision box at all

Solved it just incase anyone else has this problem when using animated body2D, you need to turn Sync to Physics off on the animatable body checkbox :smiley:

1 Like