9 posts
• Page **1** of **1**

Hi all, this might sound like a very noob question but whats the easiest way to move a sprite to a certain location {X axis} FLUIDLY. I have tried different ways also with bullet behavior but the sprite is still continuing to move - it ignores the set to X action. Im not really good with lerp also :/

**Posts:**191**Reputation:**1,873

B

8
S

4
G

1
I'm not sure what you mean by set to x action.

if you are trying to stop the bullet at a certain x position it is very possible the bullet is never at that precise x position.

The bullet moves a certain amount of pixels every tick, so it could be it's x position is never exactly the position you specify.

if you are trying to stop the bullet at a certain x position it is very possible the bullet is never at that precise x position.

The bullet moves a certain amount of pixels every tick, so it could be it's x position is never exactly the position you specify.

I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..

**Posts:**6,160**Reputation:**19,775

B

54
S

16
G

8
If you'd like to know how to use lerp, @Yann's explanation about lerp is probably the easiest to understand:

[QUOTE=Yann] Lerp is a very simple function

Lerp stands for Linear intERPolation

This function need 3 numbers parameter

lerp(a,b,t)

a and b are whatever number you want

but t goes from 0 to 1 (well it can go under and over but... let's keep things simple)

lerp(a,b,0) returns a

learp(a,b,1) returns b

the values in between 0 and 1 returns a number X between a and b such as X-a = (b-a)*t

so t describe more or less where you are in between a and b

lerp(a,b,0.5) return the middle so a+(b-a)/2

lerp(0,10,0) = 0

lerp(0,10,1) = 10

lerp(0,10,0.5) = 5

the way newt use it with

[code]sprite set X to lerp(self.X,destination,0.5*dt)[/code] is a little trick

the .X you have in the lerp is the .X you change in the expression

and 0.5*dt is always more or less the same (depending on fps)

so from step to step in the movement, destination-self.X will be shorter and shorter, so the lerp(self.X,destination,0.5*dt) will continue to move the sprite but slower and slower (ease out)

In short the only issue with this technique is that the sprite will takes time to exactly get to destination. Mathematically it should never arrive but thanks to float rounding stuff it will.

Anyway you should not rely too much on

if sprite.X = destination

that's all :D[/QUOTE]

[QUOTE=Yann] Lerp is a very simple function

Lerp stands for Linear intERPolation

This function need 3 numbers parameter

lerp(a,b,t)

a and b are whatever number you want

but t goes from 0 to 1 (well it can go under and over but... let's keep things simple)

lerp(a,b,0) returns a

learp(a,b,1) returns b

the values in between 0 and 1 returns a number X between a and b such as X-a = (b-a)*t

so t describe more or less where you are in between a and b

lerp(a,b,0.5) return the middle so a+(b-a)/2

lerp(0,10,0) = 0

lerp(0,10,1) = 10

lerp(0,10,0.5) = 5

the way newt use it with

[code]sprite set X to lerp(self.X,destination,0.5*dt)[/code] is a little trick

the .X you have in the lerp is the .X you change in the expression

and 0.5*dt is always more or less the same (depending on fps)

so from step to step in the movement, destination-self.X will be shorter and shorter, so the lerp(self.X,destination,0.5*dt) will continue to move the sprite but slower and slower (ease out)

In short the only issue with this technique is that the sprite will takes time to exactly get to destination. Mathematically it should never arrive but thanks to float rounding stuff it will.

Anyway you should not rely too much on

if sprite.X = destination

that's all :D[/QUOTE]

I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..

**Posts:**6,160**Reputation:**19,775

B

54
S

16
G

8
sprite boolean "moving" is set: set x to sprite.x+dt*instancevarspeed

or if you don't want to use speed, but time taken to get from 485 to 1700, use

sprite boolean "moving" is set: set x to sprite.x+dt*(1700-485)/instancevartime

If you have a bullet behaviour applied and don't want the sprite to move with this, set the bullet speed to 0. Or if you only want the y-portion of the movement, set x to sprite.x-cos(bullet angle of motion)*dt*bullet speed additionally.

If you want it to stop at 1700, set

sprite x greater or equal 1700: set moving to false; set x to 1700

or if you don't want to use speed, but time taken to get from 485 to 1700, use

sprite boolean "moving" is set: set x to sprite.x+dt*(1700-485)/instancevartime

If you have a bullet behaviour applied and don't want the sprite to move with this, set the bullet speed to 0. Or if you only want the y-portion of the movement, set x to sprite.x-cos(bullet angle of motion)*dt*bullet speed additionally.

If you want it to stop at 1700, set

sprite x greater or equal 1700: set moving to false; set x to 1700

Visual Novel 'Engine' in 100 Events

if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review

if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review

**Posts:**787**Reputation:**3,786

B

22
S

9
G

1
**Posts:**191**Reputation:**1,873

B

8
S

4
G

1
9 posts
• Page **1** of **1**

## Who is online |

Users browsing this forum: R0J0hound and 10 guests |