How do I make a smooth ScrollTo?

  • Hello,

    im making a small game where the you can shoot your player character from one cannon to an other.

    I added a ScrollTo behavior to my player. So far so good, but the problem is that the camara "jumps" sometimes. Im pretty sure its because of this event:

    [attachment=0:1f5v7fjz][/attachment:1f5v7fjz]

    This leads to "teleporting" the player 50px. And the camara does that to.

    Any idea how i can fix this?

    Thanks in advance

  • add an invisible object with scroll to behaviour and let it move to that point, for example "on collision with cannon"->player.scrollto disable, set cameraobject.position to player, cameraobject.scrollto enabled, cameraobject.bullet set speed 5, set angle to angle (object, cannon)

  • I like to put my scrollto behavior on a separate invisible object and then just lerp it's position to the players.

    I only use it if I need screenshake or want to track multiple objects, though. If you don't need those it's easier to just go through system and lerp your scrollx and scrolly values to the player (or anywhere else) directly.

  • add an invisible object with scroll to behaviour and let it move to that point, for example "on collision with cannon"->player.scrollto disable, set cameraobject.position to player, cameraobject.scrollto enabled, cameraobject.bullet set speed 5, set angle to angle (object, cannon)

    Thanks, but it doesnt seem to work well. If i enable the bullet behavior the cameraobject moves and doesnt stop(which is the supposed to happen for a bullet). It doesnt really solve my problem. I need a "Move towards position(Cannon.ImagepointX(0),Cannon.ImagepointY(0)) i guess

    I like to put my scrollto behavior on a separate invisible object and then just lerp it's position to the players.

    I only use it if I need screenshake or want to track multiple objects, though. If you don't need those it's easier to just go through system and lerp your scrollx and scrolly values to the player (or anywhere else) directly.

    I already tried a seperate cameraobject but coundnt get that to work. How would I learp exactly?

  • Oh, sorry. lerp is a system expression.

    From the manual: "lerp(a, b, x) Linear interpolation of a to b by x. Calculates a + x * (b - a)."

    So for smooth camera tracking, you might try System / Scroll To Position and setting X to lerp(scrollx, player.x, 0.05) and Y to lerp(scrolly, player.y, 0.05). That third value in each, (0.05 in this example) changes how fast it'll scroll. The bigger the number, the snappier it'll be.

  • Like this?

    [attachment=0:25qlknqn][/attachment:25qlknqn]

    Seems to work better, thanks

    But not perfecty, any way to optimise it?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ah, I was suggesting this as a replacement for the ScrollTo behavior. For it to work right, you'd need to remove the behavior and set your new scroll event to run every tick. It should smooth out that jump you were describing with a little tweaking. Unless I misunderstood what you're trying to do?

  • Ah, I was suggesting this as a replacement for the ScrollTo behavior. For it to work right, you'd need to remove the behavior and set your new scroll event to run every tick. It should smooth out that jump you were describing with a little tweaking. Unless I misunderstood what you're trying to do?

    Ah great, it works now

    [attachment=0:3qf3ey3k][/attachment:3qf3ey3k]

    Thank you very much

    Almost perfecty, just a little "jump" is left. If anybody got an additonally idea, please let me know.

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