I have problem with my 'jerky' movement by using "lerp"...

Get help using Construct 2

Post » Thu Sep 29, 2016 4:05 pm

Message: Avenged90x can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Hi.

I'm making logic-platform game and i want to make smooth, jerky movement - like jumping frog in my game, but i have problem with precision to keep 'PlayerObject' jumping in specified distances - like at 100 pixels for example.
I used "lerp" to make it smooth, but I'm not sure if it is good idea.. maybe i should make it in other way?

My goal is to make simply movement like: smooth move about 100 pixels on the right (or left) with little jump.

Problem is, that the lerp has digits after the decimal point - so when I'm hitting the "right arrow" key to make this movement - the player has jumping fast, but not precise and it lands (stop lerp animation) farther than it should (or closer). You can see that by tiled floor (builded on the grid)..

I made instance variable to my Player object with name: canMove to control jumps and precision. So from default "canMove" is on true, but when the lerp animation is "playing" it should be on "false" (i set this by making action after pushing "Right arrow" to make move).
So i tried to find the end point of lerp animation - i thought it is Player.X >= Player.TargetX and than set the "canMove" to "true". But i don't know what i'm doing wrong..

Im attaching my capx of this movement. So i hope someone can help me.
https://dl.dropboxusercontent.com/u/830 ... ecise.capx

And I hope that I've written quite understandable :P
B
4
Posts: 34
Reputation: 268

Post » Mon Oct 03, 2016 5:48 am

Hello.

Unfortunately, I cannot see your link for the capx, so I'm not sure that I can help. I think you might be running your event multiple times while your key is pressed. Are you familiar with "trigger once while true?" Adding this to your key press condition may solve your problem. https://www.scirra.com/manual/124/system-conditions
B
26
S
11
G
4
Posts: 30
Reputation: 3,937

Post » Mon Oct 03, 2016 9:38 am

In my opinion, it is easyer to use the LiteTween plugin.
behavior-litetween_t70700

But, that is not your qeustion. So, let me try to give a good answer.

First of, i am aware that mostly lerp gets used with a dynamic start point, a static endpoint and a static lerpfactor. A lerpfactor that has to be dt corrected. And that is not really easy.
This way the next step gets smaller and smaller (but never zero), giving some (in my eyes fake) feeling of smoothing out. But, you will have to when the target is moving. That is (if i understand right) not you case.

So, under the condition that the target is not moving, lerp can be used in much (again in my eyes) better way.
Basically using a static start, a static end and a dynamic lerp factor (that is already dt corrected in the right way)

Besides that. there is not only lerp, but also qarp and (very usefull) there is cubic.

In this example i use cubic to easy-in and easy-out a movement. I kept it as 'visual' and as 'simple' as possible.
Look at the imagepoints on the ruler.

https://drive.google.com/open?id=0B1SSu ... nZReFFzWEU

Hope this opens your eyes to new ways. Greetings.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Oct 06, 2016 11:59 am

jasmattkrz yes.. unfortunately i can't paste links because of my low number of reputation points..
Maybe on this way :D : dl dropboxusercontent com/u/8305038/Jerky%20Movement/JerkyMovementNotPrecise capx (put dots instead of spaces)

I think that i tried with that trigger "once" but I'm not sure, i must check it.

99instancesToGo i cant open your capx, because you're using newer version of C2.. unfortunately newer version doesn't work in my computer.. so i must to use r209 version..
B
4
Posts: 34
Reputation: 268

Post » Thu Oct 06, 2016 2:47 pm

I want to make a suggestion to help but really don't understand the
Avenged90x wrote:...i want to make smooth, jerky movement - like jumping frog in my game


You could use lerp() but I wouldn't use a static third variable—that smoothing wouldn't make me think of a frog jumping. I usually use lerp with instance variables so it looks like lerp(starting, finishing, progress) and put it in a deactivated group. Set progress to 0, activate the group where every tick add speed (another variable) to progress and when progress >= 1 deactivate the group.

Of course you can do this a bunch of different ways. If it is a jumping look you are going for I made these blobs with custom movement and timers, and of course animations:
Image
ImageImageImage
B
44
S
26
G
11
Posts: 520
Reputation: 10,506


Return to How do I....?

Who is online

Users browsing this forum: warmty, Yahoo [Bot] and 10 guests