Sign in to follow this  
luke88

Scaling physics with screen resolution

Recommended Posts

luke88    160
I'm currently working on a 2D (vector based) game, and I of course want the players to be able to choose any resolution they wish. While I've successfully managed to scale the graphics properly, I can't seem to figure out how to scale the physics.
Take a look at this simple projectile code to get a better understanding of what I mean:
[source lang="vb"]bullet.gravity = 0.5
bullet.speed = 1

SUB projectilePhysics
IF bullet.stage = 1 THEN
bullet.x = turret.x2
bullet.y = turret.y2
bullet.xVel = COS(bullet.angle / 180 * Pi) * (bullet.power / bullet.speed)
bullet.yVel = SIN(bullet.angle / 180 * Pi) * (bullet.power / bullet.speed)
bullet.stage = 2
ELSEIF bullet.stage = 2 THEN
bullet.x = bullet.x + bullet.xVel
bullet.y = bullet.y + bullet.yVel
IF bullet.yVel < 12 THEN bullet.yVel = bullet.yVel + (bullet.gravity / (bullet.speed * bullet.speed))
END IF
END SUB[/source]
Let's say I'm running the game in 640x480, if [source lang="vb"]bullet.power = 20.5[/source] and [source lang="vb"]bullet.angle = 270[/source] (straight up), the 'bullet' will roughly reach a height of around 480 (well, technically 0, as 480 is the bottom, and 0 is the top). Now if I were to run the game in 800x600, the 'bullet' would of course, still only reach around 480, whereas I would want it to reach around 600 (and take the same amount of time to do so). I'm unsure as to what the math would be to achieve this. I've tried various ways, but nothing seems to give the desired affect.

Any help would be greatly appreaciated [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] Edited by luke88

Share this post


Link to post
Share on other sites
Mussi    4407
Wouldn't a simple division by 480 and a multiplication by 600 do the trick? That is, divide by the height/width you designed for to get a value between 0 and 1 and then multiply by the height/width that you actually want. Don't do this in between calculations though, just when you're passing on positions to draw.

Share this post


Link to post
Share on other sites
luke88    160
Wow, that's so simple, thank you very much. I'm a bit annoyed at myself for not thinking of that. I've not tested it properly yet as my graphics scaling code works in a completely different, and ridiculous way, and I'm having to go back and change everything, but my preliminary tests suggests that it should all work fine :)
Thanks again Mussi. If I don't follow-up this post with new problems, it's safe to assume that it was all a success.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this