How do I predict and draw the future trajectory of my ship?

0 favourites
  • 5 posts
From the Asset Store
26 pixel space ships of Humans and Invadors including regular and boss space ships.
  • Hello!

    I have seen some matching topics here that tackle the same problem, but the solution there or at least how it's communicated is difficult to understand for me as math is really not my thing.

    I use the physics engine with the actual ship and a simulated ship to draw the predicted path. For the simulated ship, I loop an impulse to calculate the velocity at the current position, just to teleport it afterwards to the correct predicted position. I need impulses as there is no time in a loop passing, but force needs time.

    This works actually quite well, as long as the real ship has zero velocity. In the video, you can see that the first drawn path is the correct prediction for the ship.

    Before every calculation, I reset the position and velocity to start fresh, but once the actual ship is in motion, it appears that velocity isn't counted in correctly. That's why I added an initial impulse in the 4th event, as it made the first predicted path very correct.

    Here a video: imgur.com/a/hYhbD4l

    Here the c3p file: dropbox.com/scl/fi/naijbi9yw4u7pzyp79ap1/Spacetravel.c3p

    There appears to be some smart people here. I'd really appreciate some help or advice.

    If you feel like rewriting my event setup, you're very welcome to :)

    Thank you!!

  • In another topic I saw R0J0hound answer quite detailed and knowledgable. It's just a little too high for me. Some help would be really appreciated.

  • To predict a path basically involves repeatedly simulating frames to get the path. I think previous topics tried to simulate that, but I actually haven't tried your approach of using an impulse to simulate a frame.

    Here's the idea refined, and it seems to work great.

    The setup is to set the physics stepping mode to fixed. With that the time step is always 1/60. Then to simulate the path you'd copy an objects position and velocity and then with a loop use timestep*force for the impulse, and then manually advance the position with the velocity.

    dropbox.com/scl/fi/7o7pjwaffwty9n3u8dke0/perdict_physics_path.c3p

    You can use a larger time step but since gravity forces vary by position the resulting path will be approximate and diverge pretty quick. In the same way using framerate independent stepping mode the predicted path will vary a lot.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you so much!

    This gives a lot of insights!!

  • After studying your file and changing my setup accordingly, I realized that you multiply the gravitational pull of the moon by time step in the looped impulse. That was the puzzle piece that I missed.

    Again, thank you so much! You made my day! R0J0hound

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