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

Get help using Construct 2

### » 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
S
1
Posts: 18
Reputation: 438

### » 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
415
S
247
G
92
Posts: 25,279
Reputation: 200,817

### » 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
S
1
Posts: 18
Reputation: 438

### » 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
415
S
247
G
92
Posts: 25,279
Reputation: 200,817

### » 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
54
S
23
G
18
Posts: 2,123
Reputation: 17,200

### » 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
S
1
Posts: 18
Reputation: 438

Bump?
B
6
S
1
Posts: 18
Reputation: 438