ScrollTo lerp in front instead of behind

1 favourites
From the Asset Store
50 front view of buildings JPG - residences shops and offices - 2048x2048
  • Hi, I'm trying to come up with a calculation to make the camera not follow the player but rather proceed the player depending on direction.

    Using plain lerp makes it so the player is closer to the edge of the screen they are traveling to, but I want them closer to the opposite edge the are traveling to so they have more time to adjust to objects that they arrive at.

    Any ideas?

    This is what I have... it did NOT work :O

  • it seems like I would need to use Angle of Motion from the player to determine whether to add or subtract the X or Y.

    but honestly I was first just trying to get it to work going right - where I know it will always be adding to X - but it doesn't work either!

  • You could create a sprite to be the target. So you cam make the target be ahead of the player by say 100 pixels with this:

    every tick

    --- target: set position to player

    --- target: move 100 pixels at angle player.angleOfMotion

    Then you'd do your lerp scrolling to the target instead of the player.

  • R0J0hound

    I thought of that, but, when the player slows down I want the screen to then be centered on the player. Like what it currently does with lerp(scrollx,player.x,dt) so it visually looks like the lerp "catches up" to the player when the players speed approaches 0.

  • Ok. So instead of moving the target sprite by a fixed distance, such as 100, you could make it proportional to the speed.

    Something like:

    move 1*player.speed pixels at angle player.angleOfMotion

    That way it will be centered on the player when not moving. Probably you'd want to tweak the 1 if the screen shifts too much or two little. Another idea is to just center the target on the player when the speed is less than a value and otherwise move it by an offset.

    move player.speed<50?0:100 pixels at angle player.angleOfMotion

    Where 50 is the speed and 100 is the offset.

  • R0J0hound

    thanks! that works great, however it introduced another problem I was not aware of...

    I use Custom Movement behavior, so in order to make a Max Speed cap I do this:

    so when you are at max speed, the camera shakes violently because of constantly being set to 1 less than the cap. The player moves like the game Asteroids, so you can rotate while still moving in the direction you accelerated to. So this was my bad solution in order to turn around and apply acceleration in the opposite direction. So now need a new solution.. I could maybe make that interval smaller...

  • I added a lerp to the camera and it is better.. although the camera sprite is wobbling like crazy, but the player isn't.. so maybe its okay??

  • On second look I don't think this will work, when the player hits something that suddenly decreases its speed the screen snaps jarringly to the new speed. So I need to find a way to ease that movement... and now I'm back to the beginning of needing a lerp equation!

  • Try both - Use an object to predict your future motion based on your current vector, and have a camera object with a lerp towards that one.

    dropbox.com/s/jkb52blsbte0ckh/Smoothcameraexample.c3p

  • Maybe:

    + System: Every tick

    -> System: Scroll to (lerp(scrollx,Player.X+cos(Player.Platform.MovingAngle)×(Player.Platform.Speed),3×dt), Player.Y)

  • thanks newt for some reason your code puts my player in the top left corner when going right and the bottom right corner when going left! I'm sure I could mess with it a bit.

    also thanks oosyrag I think your solution will work! I didn't even think to use the dx and dy!

    I still get that shakey problem on the momentum sprite because the the max speed thing, but it doesn't matter since the scrollTo is on the camera. And a nice side effect is that when my player hits things and the speed suddenly drops it creates a camera shake effect! awesome thanks!

    Do either of you remember a custom Behavior called Spaceship Behavior? I don't think it's supported anymore, but do you have any idea how they capped the maxspeed? For a movement that Accelerates at self.angle?

    The problem is if your max speed is 300, when you're at 300 you can no longer accelerate in any direction. The only way to slow down is to accelerate in the opposite direction. I played with this a lot. The best I found was to knock the speed down a hair in order always be accelerating a little, that way you can change direction or slow down. My way works for now, but I would like a more "real" solution if there is one! thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • jobel

    I was working on a sample when oosyrag and newt made their suggestions - and came up with something very similar.

    I dont remember a spaceship behavior, but my sample works the way I think a spaceship should without any shake at max speed...

    https://www.rieperts.com/games/forum/spacebackground2.capx

  • You can also see how max speed was done in this example from a while ago - construct.net/en/forum/construct-3/how-do-i-8/spaceship-movement-130957 (also by r0j0).

    It doesn't use any behaviors, but you can see how it works very clearly,. It would apply very similarly to custom movement's dx and dy.

  • thanks AllanR yep that works!

    thank you oosyrag I knew R0J0hound had an example of it somewhere! seriously I wish there was a R0J0hound-only channel with all examples, helpful tips and maths!! it would be a great resource!

    I'm not having a good experience searching the forums with this new website, its really hard to find stuff, it used to be a lot easier... I miss old scirra.com :(

  • AllanR - I noticed your tiling system for your spacebackground... a totally different approach, here's how I am doing it...

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