Some math help needed: distance between two moving objects.

For questions about using Classic.

Post » Wed Dec 16, 2009 11:29 am

I'll try to explain as best I can. Maybe I can word this in a way that best resembles a word problem even, making it more relatable to the more math-savvy Construct users here.

I have three objects, and every single one is imperative to my idea. I have a player object, an arm, and a hand. This employs my grappling idea. The character reaches his hand forward to grab onto grapple points. To do this, a hand bullet object is shot from the player object. But we can't just have a floating hand, right? I was going to have a third object, an arm, but I have no idea how to make it stretch out between the player and hand object.

How can I make the arm object's width stretch out between these two moving objects? I can't figure this out for the life of me, and I can't just try figuring it out based on .X positions since the player could fire off the hand object in mid-fall or something. (Not that I ever figured out how to get it to work with just .X positions anyway shooting it out straight horizontally.)

I'm guessing this problem will have to do with cos, or... cosine or... whatever... I have no idea. I hope I explained this well enough for anyone reading this to understand what I'm doing. ^^;
B
4
S
2
G
4
Posts: 164
Reputation: 1,878

Post » Wed Dec 16, 2009 11:38 am

Put the hotspot to the middle left of the arm object (hit 4 on the num pad with the hot spot tool).

Have an image point on the player where you want the arm attached (let's call it "ArmPoint").

Always position the arm object at ArmPoint, and set its width to distance(player.x, player.y, hand.x, hand.y), and set its angle to angle(player.x, player.y, hand.x, hand.y). That should be roughly what you want, might need some tweaking of hotspots and imagepoints.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,508

Post » Wed Dec 16, 2009 11:57 am

[quote:18a8mo0q]Always position the arm object at ArmPoint, and set its width to distance(player.x, player.y, hand.x, hand.y)[/quote:18a8mo0q]

There's actually a thing for something like that!? Seriously!? There's no manual complex mathematics involved?? I WONDERED if there was something like that, but I doubted it, and couldn't find anything like that when I tried looking...

But that worked precisely and EXACTLY like I wanted. ^_^ Awesome. Thanks. I wouldn't have even had to ask if I knew about that "distance" thing. Is there anywhere where there's a complete, comprehensive list of all those sorts of things? Like ".count", "distance", or anything? Is there a full list on the wiki or anything?
B
4
S
2
G
4
Posts: 164
Reputation: 1,878

Post » Wed Dec 16, 2009 12:18 pm

[quote="Kisai":1sbsy0nq]Is there anywhere where there's a complete, comprehensive list of all those sorts of things? Like ".count", "distance", or anything? Is there a full list on the wiki or anything?[/quote:1sbsy0nq]

Yes there is :)

http://sourceforge.net/apps/mediawiki/c ... xpressions
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Wed Dec 16, 2009 12:33 pm

Whoa. Awesome. ^_^ Thanks.
B
4
S
2
G
4
Posts: 164
Reputation: 1,878

Post » Wed Dec 16, 2009 2:06 pm

There is actually some maths going on inside the distance() and angle() expressions, but they hide that, they're just the intuitive distance-between and angle-to calculators. So really you're using some math, but its given a nice name so it doesnt scare anyone :)

For the record, distance(x1, y1, x2, y2) is sqrt((x2-x1)^2+(y2-y1)^2) and angle(x1, y1, x2, y2) is atan2(y2-y1, x2-x1) (atan2 does inside itself some more stuff than just atan too).
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,508


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests