Set speed of movement without using any behaviours?

For questions about using Classic.

Post » Tue Apr 28, 2009 5:13 pm

When I set condition "Move at angle", for example, or "Rotate at angle", the object quickly jumps to point. But I want it moves smoothly to see his movement.
How to make that? How to set his speed (i suppose) WITHOUT using any behaviour?!
:roll:

Thanks!
B
2
G
3
Posts: 30
Reputation: 910

Post » Tue Apr 28, 2009 5:37 pm

Use TimeDelta system expression.

It is basically time between two frames. If you multiply your speed variable, say, PlayerSpeed, with TimeDelta, the player will move by the amount of pixels he would have made in that time (frame).

Move at Player.Angle for Player.Value('Speed')*TimeDelta

Try it out.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Tue Apr 28, 2009 6:31 pm

Mipey, i think he means acceleration. to make acceleration, you have to always set your object to .x+'speed', and have other events which gradually change the speed value.Only multiply by timedelta if you want your game to be framerate independant (ie. Lag which skips frames instead of slowing the entire game down.) timedelta has nothing to do with speed of movement, it's only there to account for varied game framerates.
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

Post » Tue Apr 28, 2009 6:53 pm

[quote="Davioware":swt1du4n]Mipey, i think he means acceleration.[/quote:swt1du4n]
I pretty much believe its she, and to the point using Time Delta is good to make it look same on different Refresh Rates.
B
4
S
2
G
4
Posts: 719
Reputation: 2,938

Post » Wed Apr 29, 2009 3:31 am

Why not use a behavior? :P That seems the obvious thing to do. The bullet behavior would be suitable. Or, use Mipey's suggestion, which is basically to move the object a small step every tick (which is what the behavior does).
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,518

Post » Wed Apr 29, 2009 10:20 am

Thanks to all for help ! :D
Timedelta works properly. I've set both acceleration and speed of object's movement and I'm satisfied with the result :)
About behaviours - I use it sometimes, but there're situations when better to make it yourself than use pre-written behaviour.
B
2
G
3
Posts: 30
Reputation: 910

Post » Wed Apr 29, 2009 11:48 am

Sometimes I like to make custom movement for things that would otherwise work perfectly with a behaviour... usually because it's fun xD

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
45
S
17
G
37
Posts: 2,853
Reputation: 25,966

Post » Wed Apr 29, 2009 7:09 pm

I still have some questions :roll:
For example, i want to make that the sprite moves every 64 pixels (as grid movement but not using this behavior). I set "when press Right arrow key then move 64 pixels at angle 0" - sprite jumps these 64 pixels. Then I add Timedelta and it smoothly moves, but not exactly 64. It moves while i press key, but when i released - it stops in random place.
How to make that the sprite moves smoothly and on the same number of pixels? Another words - grid movement but without using any behaviors?...
What do you think? :)

p.s. this is my unsuccssesful attempt - [url:1cb0rk0l]http://willhostforfood.com/access.php?fileid=64568[/url:1cb0rk0l]

p.p.s sorry for my bad english :oops:
B
2
G
3
Posts: 30
Reputation: 910

Post » Wed Apr 29, 2009 8:04 pm

[quote="orcheliya":20tkq6ep]i want to make that the sprite moves every 64 pixels

How to make that the sprite moves smoothly and on the same number of pixels?[/quote:20tkq6ep]

Does this work for you, maybe? http://dl.getdropbox.com/u/529356/gridmove.cap
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Wed Apr 29, 2009 8:05 pm

In that case you have to set it up to keep running until it's made 64 pixels. Make an event that is run whenever a private variable contains the right value.

Like this (assuming you have a private variable 'Status'):
[code:12glmkv3]
//triggering event
+Right Arrow is pressed
+Player('Status') = "Idle" // Only move the player if it is not already moving
>Player('Status') = "MoveRight" // Tell it to start moving

//actual moving event
+Player('Status') = "MoveRight" //check if the player is set to move right
+Player.X < Player('OldPositionX')+64 //Keep moving until the goal is reached
>Player.X = Player.X + Player('Speed') * TimeDelta
++Player.X > Player('OldPositionX')+64 //Whoops, a little over the goal; it means it has reached it
>>Player.X = Player('OldPositionX') + 64 //This is to round the player's position up
>>Player('Status') = "Idle" //Tell it to stop moving
>> Player('OldPositionX') = Player.X //Remember the new position

[/code:12glmkv3]
As always, + are conditions, ++ subevents, > actions, >> subevent actions
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest