Help with equation for movement overshooting

0 favourites
  • 3 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • [attachment=0:bhl8dxt8][/attachment:bhl8dxt8]

    So, I've got a line of code highlighted that's causing a problem for me. It works, about 98% of the time. But its a pretty core piece of functionality. What I'm doing is moving my character from point to point on the screen, with spikes that cause death on either side. The code is supposed to adjust its location to the waypoint's Y over the time it takes for the waypoint to cross the Y. About 1 out of 50 times though it overshoots. I'm assuming there's a better way to do this than what I managed to mash out, so help?

    The character only moves on the Y axis, and the waypoints have a fixed Y but move on the X axis.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It's a little hard to understand what's happening just based on the code and your description. In any case it's NOT a complete view. Looks like your using some variables but, it's not clear what they represent. Can you post a capx?

  • Turns out I was a little hasty. Basically I was rolling my own movement code when I could have just used the Physics behavior. That simplified things and fixed my bug.

    Basically what you're looking at in the photo is the highlighted line. It takes the X and Y of the Waypoint and calculates how much to move the character by based on how far the waypoint is away. So if the waypoint is 5 units away from the character's X and 5 units away from the character's Y, the character moves so that the x difference will be 0 when the y difference is 0. See this video: "www.youtube.com/watch?v=0TecJZYX75c&list=UUkC_TF5BPrxTAXt0M5Pxy0A" Thanks though!

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