How do I move player to a location inside of a moving box

Get help using Construct 2

Post » Thu Oct 05, 2017 6:07 am

Hi - I'm working on a top down game that uses click-to-move controls. There are large moving boats in my game and I'm trying to figure out how I can get my player to move to a certain location on the large boat, while the boat is moving.

I figured out a hack solution, where I calculated the displacement from the boats position to where I clicked to move to on the boat.
XDisplacement: (target.x - boat.x)
YDisplacement: (target.y - boat.y).

Then I move my player to this new position every tick
X: Boat.X - XDisplacement
Y: Boat.Y - YDisplacement
This keeps up to date the relative position on the boat that I ordered my player to moveTo, even if the boat is moving.

Here's an example of how it currently looks (but it's fairly odd) - https://i.imgur.com/l4onOBZ.gifv
There's a parabola effect I am trying to get rid of. Preferrably I'd like the player to move in a direct route toward the "new" location on the boat. The speed of the boat, and the speed of the player are both constant.

Does anyone have any other ideas on how this can be achieved?

Thanks in advance!
B
91
S
31
G
11
Posts: 101
Reputation: 11,362

Post » Thu Oct 05, 2017 9:58 am

I think there always will be a "parabola effect". You can minimize it a little, but it will still be quite noticeable.
If you can predict how the boat is moving and calculate where the target location will be at the end of the movement, then you can move your character in straight line directly to that position.
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
19
S
9
G
158
Posts: 2,401
Reputation: 84,429

Post » Thu Oct 05, 2017 11:36 am

Hey @Badmiracle!

I'm not sure I get what you need, but it may be something like this example I've posted in the forum some years ago:

https://www.dropbox.com/s/jives77kcpmus ... .capx?dl=0

Hope this helps. Cheers!
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
22
S
6
G
3
Posts: 722
Reputation: 4,026

Post » Thu Oct 05, 2017 12:50 pm

Scrap my previous comment, brunopalermo gave me an idea how to do this :)

I made a demo:
http://doptrix.com/C2/BoatWalking/
capx

Shadow object is for simplicity and to demonstrate the idea. You can do it without it.
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
19
S
9
G
158
Posts: 2,401
Reputation: 84,429

Post » Thu Oct 05, 2017 1:38 pm

Nice example, @dop2000!
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
22
S
6
G
3
Posts: 722
Reputation: 4,026

Post » Fri Oct 06, 2017 5:25 am

@Badmiracle

I had the same problem while ago and this is how I resolved, I hope it helps

https://www.dropbox.com/s/gyv2pkcz6im39dx/Set%20Position%20in%20a%20moving%20Boat.capx?dl=0

you can change the Movement speed changing the Values on the Global variable "Speed"
B
54
S
33
G
95
Posts: 435
Reputation: 53,546

Post » Sat Oct 07, 2017 12:06 am

@dop2000
@brunopalermo
@tarek2

All GOD's. Interesting methods, thanks guys.
B
91
S
31
G
11
Posts: 101
Reputation: 11,362

Post » Sat Oct 07, 2017 8:39 pm

Glad to help!
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
22
S
6
G
3
Posts: 722
Reputation: 4,026


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 3 guests