0 Favourites

# Some math help needed: distance between two moving objects.

This forum is currently in read-only mode.
• 6 posts
• 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. ^^;

• 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.

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

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?

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

Construct 3 users don't see these ads
• 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?

Yes there is

http://sourceforge.net/apps/mediawiki/c ... xpressions

• Whoa. Awesome. ^_^ Thanks.

• 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).

• 6 posts