# Move Object on a moving Object

This forum is currently in read-only mode.
0 Favourites
• 7 posts
• Hi,

Sorry for my bad english.

I have a moveable Object that is controlled by the Player. Now I want a sliding door on that moving Object.

If the Object is not moving at all, there is not a problem. the Door slides from one ImagePoint to the other.

lerp(Door.X, Player.ImagePointX("door_open"), 1 - 0.008^TimeDelta)

lerp(Door.Y, Player.ImagePointY("door_open"), 1 - 0.008^TimeDelta)

But if the Base Object is moving the door does not slide to the right point.

Please can someone help me out?

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• It would be helpful to have more information. Does your vehicle rotate? Or is it always facing the same direction? If you could provide an example .cap of what you're trying to do, that would be very helpful as well.

• The player object is a physics object which is able to move, rotate, bounce etc.

• Ah, I see . Well, the math for that is way over my head.

What I would recommend is that you create an animation of your door moving open and closed. That way you can just play the animation, and it will appear to move properly no matter which direction it is facing, and will remain attached to the proper location at all times (instead of floating around with lerp).

• [quote:2k4zhxpv]lerp(Door.X, Player.ImagePointX("door_open"), 1 - 0.008^TimeDelta)

lerp(Door.Y, Player.ImagePointY("door_open"), 1 - 0.008^TimeDelta)

That looks right. You might check your image points in the image editor, and make an event that sets its angle to the base objects angle.

Also 1-0.008 is pretty slow, might bump that up a bit.

• In doing my own tests with this (using that same formula), the lerp causes the door to lag behind the image point on the player when the player is moving, even if the lerp amount is large.

I even tried to change it up so that all the calculations for door movement were "local" and relative to player space, rather than targeting the player image points in world space. It was a little better, but still laggy.

I'm sure there is a formula out there that will do this perfectly, and I am also sure that formula is way out of range of my math skills. So as I mentioned before, I think the simplest and most accurate method would be to make door opening and door closing animations for your door sprite.

(If Construct had any sort of parenting ability, you could parent the player to the door and move the door child locally along it's own Y axis relative to the player. All other positioning and rotation of the player parent would be automatically transferred to the door. Unfortunately, Construct doesn't do that... so, uh, this is a moot point I guess )

• clamp(lerp(Door.X, Player.ImagePointX("door_open"), 1 - 0.008^TimeDelta),min,max)

clamp(lerp(Door.Y, Player.ImagePointY("door_open"), 1 - 0.008^TimeDelta),min,max)

Should keep it within the general area, but keep in mind order matters, so that action should be last on the event.

Also there will be a lot of "play" if the object is rotating, so you might want to keep the lerp to a single axis. Since its a door and all.