arbetrary axis and distance traveled.

Get help using Construct 2

Post » Thu Feb 06, 2014 7:35 pm

Hello everyone,

I have quite a problem I have been working on for the last few days. In a nut shell, I have a game where gravity changes (is constantly changing. I am using physics behaviors on all objects.

Basically, at the beginning of the event sheet, I determine need to determine what surfaces the player is touching (up,down,left,right) and what directions the player is moving relative to the force of gravity (up,down,left,right)

I have solved how to determine collision surfaces and what side they are on. I also feel like I know how to solve the other problem.

my events look like this:

-----

//finding the angle the player is moving and the distance traveled

player travel angle = system angle(oldx,oldY, currentX,currentY)
player travel distance = system distance(old vector, new vector)

//checking if player is moving "up"(given gravity can be at any angle and up is the way gravity is not pulling)

if travel distance is greater than 0 (make sure the player is moving)
and if the smallest difference between the angle of gravity and the players travel angle is greater than 90.


-------

I wouldn't mind being able to check what the distance traveled along the arbitrary axis of gravity would be either, but I can't seem to figure out how to calculate that. Normally if gravity is down it is easy to see how far along each axis an object has traveled because the angle of gravity is aligned with x and y (therefore if y distance is less than 0 it follows that the player is moving in an upward direction)

Anyway if anyone is familiar with this stuff let me know. I can't share the capx due to nondisclosure stuff.

thanks
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,153

Post » Thu Feb 06, 2014 8:59 pm

Here's the formula, it's a vector projection if you wish to google more about the math behind it.

Distance traveled at anglle = (curx-oldx)*cos(angle) + (cury-oldy)*sin(angle)
B
92
S
32
G
109
Posts: 5,294
Reputation: 70,999

Post » Thu Feb 06, 2014 10:06 pm

Thank you! I looked for the better part of 3 hours for that formula but I didn't even know how to phrase my question into google. vector projection... I kept looking for something about surface normals. Much obliged.
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,153


Return to How do I....?

Who is online

Users browsing this forum: Artcadev, Yahoo [Bot] and 31 guests