Move Object on a moving Object

For questions about using Classic.

Post » Sun May 15, 2011 12:40 pm

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?
B
7
S
2
G
2
Posts: 45
Reputation: 1,465

Post » Sun May 15, 2011 3:39 pm

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.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sun May 15, 2011 3:54 pm

The player object is a physics object which is able to move, rotate, bounce etc.
B
7
S
2
G
2
Posts: 45
Reputation: 1,465

Post » Sun May 15, 2011 4:27 pm

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).
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sun May 15, 2011 4:50 pm

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

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.
Image Image
B
161
S
48
G
91
Posts: 7,359
Reputation: 67,273

Post » Sun May 15, 2011 6:10 pm

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 :P)
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sun May 15, 2011 7:50 pm

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.
Image Image
B
161
S
48
G
91
Posts: 7,359
Reputation: 67,273


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests