How do I move sprite X pixels in X seconds?

Get help using Construct 2

Post » Mon Jul 11, 2016 8:49 pm

All the help, tutorials, examples i've seen deal with moving to mouse, or object, or something else that requires multiple events and/or actions.

All i need is to move a sprite from:
X 480, Y 270 to X 480, Y 80 in 1.5 seconds and stop.

I've tried 8 direction, bullet and other actions that will make it snap to that posititon or toward that position but then it keeps going.

Thanks for any help on this.
B
38
S
18
G
19
Posts: 664
Reputation: 14,112

Post » Mon Jul 11, 2016 9:01 pm

LiteTween is an extremely versatile plugin. It can do this easily.
viewtopic.php?t=70700&start=0
ImageImageImage
B
71
S
22
G
248
Posts: 3,758
Reputation: 138,067

Post » Mon Jul 11, 2016 9:04 pm

Something like
Set Player Y to Player.Y+sin(Player.Angle)*distance in pixels/seconds

Now I'm not sure about the seconds part

I might completely off as well.
B
43
S
12
G
14
Posts: 488
Reputation: 10,570

Post » Mon Jul 11, 2016 9:12 pm

You can use the timer behavior, or set up your own timer/counter variable.

Instance Variables:
Duration=1.5
IsMoving=false

(On Trigger, Object IsMoving=false)
Start timer for Self.Duration seconds
Set Object.IsMoving=true

(Object IsMoving=true)
Set Object Y position to lerp(270, 80, Self.Timer.CurrentTime/Self.Duration)

(Object OnTimer)
Set Object.IsMoving=false
Set Object Y position to 80

This does take 3 events though. Recommend also having start position and end position as instance variables, which you set upon triggering the first event
Mistakes were made.
B
53
S
27
G
114
Posts: 1,697
Reputation: 64,442

Post » Tue Jul 12, 2016 2:49 am

Thanks for the replies. This could work.
B
38
S
18
G
19
Posts: 664
Reputation: 14,112


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 23 guests