move object in specific time

For questions about using Classic.

Post » Tue Jun 05, 2012 12:28 pm

I have another problem.
I can easy move object - on click, then I "set position" on X and Y and object move where I want.
But can I make it that it will took for example 2 seconds? so object will move smoothy?
thanks
B
4
S
2
G
1
Posts: 143
Reputation: 1,211

Post » Tue Jun 05, 2012 12:33 pm

If you want an object to move like that, you might want to go for bullet behavior and set direction and speed.

Is this what you are asking for?
B
2
G
1
Posts: 38
Reputation: 526

Post » Tue Jun 05, 2012 2:16 pm

I tried that, but not succesfull :(

I have on object, for example on place XY(50,50). and when I click on it, I want this object move to XY(100,100), but not immediately, but for example for few seconds.
I dont know how to set bullet, for me it moves only from one place to right and does not stop it on place where i want
B
4
S
2
G
1
Posts: 143
Reputation: 1,211

Post » Tue Jun 05, 2012 2:27 pm

The rotate expression actually works well for this. It's designed for angles but it can be used for anything pretty much.

Try setting the X and Y to: RotateAngle(Sprite.X, 100, 2)

Where Sprite.X is the starting position (so Sprite.Y for Y), and 100 is the destination, and 2 is the pixels to move by each tick.

Hope that helps!
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Wed Jun 06, 2012 1:36 pm

I tried it: http://www.datafilehost.com/download-8314f3da.html
but still it does not work for me :( dont know what i am doing wrong
B
4
S
2
G
1
Posts: 143
Reputation: 1,211

Post » Wed Jun 06, 2012 1:42 pm

Hi try using RTS behavior, set all params until you get desired response, dont forget unmark rotation

look on this example how i move the item for each menu option...

http://www.scirra.com/forum/a-nice-titlemenu_topic51492.html
B
4
S
1
G
1
Posts: 69
Reputation: 863

Post » Wed Jun 06, 2012 4:28 pm

thanks, rts behavior works ok and it is what i need,
thanks again!
B
4
S
2
G
1
Posts: 143
Reputation: 1,211

Post » Wed Jun 06, 2012 5:32 pm

@joxer
I recommend reading the Construct wiki. It helps a lot understanding the concepts of "tick based" and "time based". The key to time based actions is "TimeDelta". http://sourceforge.net/apps/mediawiki/construct/index.php?title=TimeDelta

@Jayjay
Just in case you're curious, there's another way to move something over time by combining "lerp" with "TimeDelta".
lerp(a, b, t) interpolates between a and b at t, with t ranging from 0 to 1. t=0 results in a, t=1 results in b.
If you add TimeDelta to a zero-initialised variable on every tick, it will be 1 after one second. To let it reach 1 after two seconds, you would add '0.5 * TimeDelta' instead.

This would move the sprite horizontally from 200 to 100 in two seconds (pseudo code):
+ myVariable less than 1
-> Add 0.5 * TimeDelta to myVariable
-> Set Sprite.X to lerp(200, 100, myVariable)

EDIT: And if this is too confusing, it might even give you more accuracy if you'd let myVariable count to the needed seconds. But then you need to divide myVariable by the correct number in "lerp". This example would move horizontally from 64 to 211 in 3 seconds:
+ myVariable less than 3
-> Add TimeDelta to myVariable
-> Set Sprite.X to lerp(64, 211, myVariable / 3)
tulamide2012-06-06 17:38:52
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Thu Jun 07, 2012 10:59 am

tulamide: thanks,
your construct knowledges are awesome!
B
4
S
2
G
1
Posts: 143
Reputation: 1,211

Post » Mon Jun 11, 2012 7:13 am

@tulamide thanks, that's a nice way of doing it too!
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests