arbetrary axis and distance traveled.

0 favourites
  • 3 posts
  • 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.


  • Try Construct 3

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

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

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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)