1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Windows View not following object because of high speed

Discussion in 'Programming' started by peceecar, Jun 25, 2019.

  1. peceecar

    peceecar Member

    Joined:
    Jun 11, 2019
    Posts:
    5
    Hello guys, so I have this 2d top down starship game and the thing is everything works fine for now but I use this code In the step event to follow the player because the player ship is almost always outside the room borders. The only problem is the player object often exceeds speeds of up to 5000-10000 and this sometimes causes the view to slowly lag behind the player as the ship accelerates slowly outside the view. Travel distance between planets is huge and I really want this to work with such high speeds (usually the player would choose 200-300 speed to avoid crashing into things and having better control) but even at those speeds the view still lags behind massively and I see the ship usually at the end of the view or outside. Anyway to fix this? I don't mind if it doesn't follow him smoothly the player just has to be always at the center of the view. Thank you.

    This is the code in the step event that I use to follow the player:

    view_xview = obj_player.x - view_wview/2
    view_yview = obj_player.y - view_hview/2
     
  2. JackTurbo

    JackTurbo Member

    Joined:
    Oct 19, 2016
    Posts:
    821
    Try shifting that code into the end step event.

    What might be happening is that your camera control object might be centering the view on the player object before the player object has updated its position.
     
    peceecar likes this.
  3. peceecar

    peceecar Member

    Joined:
    Jun 11, 2019
    Posts:
    5
    Thanks man that worked, can't believe it was something so simple I spent 3 hours fiddling around even with camera objects trying to make this work :D
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice