Character Jitter when using lerp() on my Physics Sprite.

0 favourites
  • 15 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • Character Jitter when using lerp() on my Physics Sprite.

    Basically, it looks like this using the simple lerp function on set position: lerp(Self.X,Sprite.X,0.3) & lerp(Self.Y,Sprite.Y,0.3)

    I've tried messing with the 0.3 value, but nothing really works.

    See how it pops. And here is it when I just have the set position to Sprite.X, and Sprite.Y

    Smooth animations and framerate.

    And here it is with no camera move.

    Also smooth.

    Now I have achieved this same effect in this game I made using Playcanvas, but what I did was use simple math like finding the difference between the two points, then dividing it by a variable that controls the speed. For instance:

    (Self.X-Sprite.X)/thisSpeed[/code:8pgfygbc]
    
    Here is a game where I used a different code set up and used basic math functions to make it work.
    https://robotpencil.itch.io/telemega
    
    I've used it in other games I made and it works great. I just need to know if there are basic math functions I could use like +-*/
  • It's not clear from your gifs which object is Sprite and which is the Character?

    Is the movement smooth if you disable Physics behavior?

    You should avoid changing x,y position for Physics objects, directly or with other behaviors like Bullet, Sine etc.

    Ideally physics objects should only be moved using Physics actions like Apply Force, Apply Impulse, Set Velocity etc.

    See this demo for example - the ball is moved to mouse position using impulses (last 3 events):

    https://www.dropbox.com/s/9cdcj8omeurgs ... .capx?dl=0

    Also, to ensure consistent movement on different framerates, use lerp with dt:

    lerp(Self.X,Sprite.X, dt*10)

  • It's not clear from your gifs which object is Sprite and which is the Character?

    Is the movement smooth if you disable Physics behavior?

    You should avoid changing x,y position for Physics objects, directly or with other behaviors like Bullet, Sine etc.

    Ideally physics objects should only be moved using Physics actions like Apply Force, Apply Impulse, Set Velocity etc.

    See this demo for example - the ball is moved to mouse position using impulses (last 3 events):

    https://www.dropbox.com/s/9cdcj8omeurgs ... .capx?dl=0

    Also, to ensure consistent movement on different framerates, use lerp with dt:

    lerp(Self.X,Sprite.X, dt*10)

    Thanks for the response. So what I've done is applied physics to my character ( The mech ) and made a sprite that scrolls by following the mech.

    Just occurred to me to share the file for help. Here it is! >> dropbox.com/s/gw56nkhazc5u2 ... x.c3p?dl=0

    Also I tried the change you suggested and it didn't work <img src="{SMILIES_PATH}/icon_e_sad.gif" alt=":(" title="Sad" />

  • Wait, I don't understand. Why do you need the second sprite? Is it for scrolling only?

    So the Mech moves smoothly and jitter only happens when you add scrolling?

    Why don't you try this:

    System->Scroll to X -> lerp(scrollX, Mech.X, dt*4)

    System->Scroll to Y -> lerp(scrollY, Mech.Y, dt*4)

    Also, the link you posted if broken.

  • Wait, I don't understand. Why do you need the second sprite? Is it for scrolling only?

    So the Mech moves smoothly and jitter only happens when you add scrolling?

    Why don't you try this:

    System->Scroll to X -> lerp(scrollX, Mech.X, dt*4)

    System->Scroll to Y -> lerp(scrollY, Mech.Y, dt*4)

    Also, the link you posted if broken.

    First of all... your solution is dope! Didn't know I could do that instead lol I was following a tutorial that had the 'camera' follow the player. But if the system can do it, then why make a camera. Either case, it still jitters. But now I have the system follow the player. But having a slight Delay would be nice.

    Second of all DOH on the broken link! Try this one. >> dropbox.com/s/gw56nkhazc5u2jw/umsd-remix.c3p

  • Yeah, for some reason when you use Physics, jitter happens.

    Although it looks like the sprite moves with constant speed, on some frames its x,y coordinates are not updating:

    X.............dt

    2410 0.016657

    2421 0.016676

    2421 0.016625

    2431 0.01665

    2442 0.016645

    2452 0.016638

    2463 0.016682

    2474 0.016693

    2484 0.016655

    2495 0.0166

    2495 0.016657

    2505 0.016651

    2516 0.016657

    I don't know why this happens, but I'm guessing that's what causing the jitter when scrolling.

    Why are using Physics anyway? With 8-Direction behavior scrolling works perfectly.

  • Physics are poor for movement of your protagonist, unless you make a game about ball or combination of figures that are Jointed together in a logical way which doesn't seems to be the case here.

    Use 8-Direction as suggested or use Platformer behavior (You can still make your protagonist fly with it. Can be tricky tho)

    If you just want your character to interact with Physical objects there's no need to use Physical Behavior for him. You can just make your own collisions.

    Just try to avoid using Physical behavior too much as it can hurt performance a lot.

  • So I used another editor and use physics to move my main and it seems to perform great. So I assumed the same with construct. The editor I use is Playcanvas but what I lose out on is the intuitive 2d art making. Construct has a lot of great features for 2d and was working fine until this. Not sure why it's jittering but it's no big deal. The set position is fine.

    I like the idea of 8 (or 4) direction movement but applying force seemed like a simple solution to the type of movement I'm after and kept the code lighter.

    I'll play around with it today and report later.

    Thanks again guys. You f'n rock!!!

  • There was something wrong with your project, some bug maybe. I created a new project with the same Physics movement and scrolling and couldn't reproduce the jittering.

    So yeah, use 8-Direction and everything will be fine.

  • Maybe you are right! I'll do some more tests to be sure. And report back!

    It may be that I scaled my sprite to be smaller.

  • There was something wrong with your project, some bug maybe. I created a new project with the same Physics movement and scrolling and couldn't reproduce the jittering.

    So yeah, use 8-Direction and everything will be fine.

    Actually, I think it has something to do with animation. Watch here is lerp without animation on my sprites.

    You can see as he slides on the platform it's fine. NOW, once I added a 4 frame animation on the idle at speed of 4, POPAGE.

    Here is the project file to test yourself. I did start from scratch too. >>

     https://www.dropbox.com/s/7rj6upn1rrtkhgd/testPhysicsControls.c3p?dl=0
    [/code:1yatzy7n]
    So I'm thinking there is some weirdness with the physics engine + animation + scrolling, almost like the animations lag behind. Not sure why though and I would love for people to replicate this and see if they have this bug occur for them.
    
    Now Using 8 direction and Platform controls do an acceleration approach, that isn't ideal for the controls I want. Meaning that if I press and hold a button it will keep accelerating the character in the respected direction, whereas the controls that I want should be on key tap. Press up, go up. Press and hold up, go up, but begin to fall since holding the button shouldn't do anything. 
    
    I can obviously code it so that once you pressed a button you should slow down. But I would only do this for the sake of a smooth camera move and the code/logic made to replicate the controls I'm looking for to me seems like it'll bloat the event page. 
    
    Thanks again for the awesomeness yall, let me know what's up! Also reported this as a bug so perhaps in the next patch this will be fixed and BAM lerped Physics yo!
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I have figured it out perfectly using the platform controls! Too bad the force stuff isn't applicable right out of the box, but this works fine!

    Thanks again to everyone who helped me out!

    The physics lerp follow is still a bug, but no worries this will work for me

  • You can do real wonders with Platformer Behavior.

    I'm currently working on Platformer myself and there's too things out-of-the-normal. Otherwise where's the fun?

  • robotpencil I think you can do the same with 8-Direction. Disable standard controls, set acceleration=10000, deceleration=0, On key pressed simulate controls.

  • robotpencil I think you can do the same with 8-Direction. Disable standard controls, set acceleration=10000, deceleration=0, On key pressed simulate controls.

    To clarify,

    I started with 8 directions, the problem was no gravity. So I switched to the platform since I didn't feel the need to program gravity since it was already built in. Seemed easier to overcome the jump up(as many times as you like) and jump down mechanics. Which was pretty simple.

    Again the best solution would have been if the force physics didn't delay the lerp. But I'm discovering that having a lerp camera at such high speeds may not be needed at all lol. But we'll see what's up!

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