How do I get the current X speed in pixels per frame?

Get help using Construct 2

Post » Mon Aug 11, 2014 2:01 pm

How do I get the current X speed of an object in pixels per frame?
I can only find the current X speed per second, so I've tried to devide that by "fps" (playerobject.Platform.VectorX/fps), but that didn't seem to work for some reason (I'd really like to know why)

Does anyone have a solution?

Thanks,
B
6
Posts: 18
Reputation: 288

Post » Mon Aug 11, 2014 2:09 pm

The distance covered per frame is calculated as pixels_per_second * dt, so just divide by dt to get the per-frame pixel step.
Scirra Founder
B
395
S
231
G
88
Posts: 24,367
Reputation: 193,684

Post » Mon Aug 11, 2014 2:29 pm

Thanks a lot, but it didn't seem to do it.
This is where I've used it:

If obj_player is mirrored: for obj_cam - Set X to "lerp(Self.X, obj_player.X-150, (0.006 * 4)) + (obj_player.Platform.VectorX/dt)"
If obj_player is not mirrored: for obj_cam - Set X to "lerp(Self.X, obj_player.X+150, (0.006 * 4)) + (obj_player.Platform.VectorX/dt)"
B
6
Posts: 18
Reputation: 288

Post » Mon Aug 11, 2014 2:31 pm

I've no idea what you're trying to do, but dividing a speed in pixels per second by dt to get pixels per frame is correct.
Scirra Founder
B
395
S
231
G
88
Posts: 24,367
Reputation: 193,684

Post » Mon Aug 11, 2014 2:41 pm

Lerp(a, b, x) is a formula where x is not in pixel per seconds nor pixels per frame, it is a numerical ratio with no units, so dividing it by dt is of no use (using lerp this way is also something I would never ever recommand, no idea why everyone is using it like that).

If you explain what you are trying to achieve, we might find a better way to do it.
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Mon Aug 11, 2014 2:46 pm

Thanks Aphrodite, but I want the camera to focus on the player -150 when the player is facing left and +150 when the player is facing right.
But the problem is that the camera can't keep up with the speed of the player so I thought that adding the speed of the player would fix that (which it did, when I replaced dt with 60 (because the game ran at around 60 fps)).
The problem is that the game doesn't always run at 60 fps, so that's not a solution.
B
6
Posts: 18
Reputation: 288

Post » Fri Aug 15, 2014 4:26 pm

Bump?
B
6
Posts: 18
Reputation: 288


Return to How do I....?

Who is online

Users browsing this forum: eochranek, fearfulelephants and 15 guests