Public Group

# Acceleration/Velocity normalisation and movement problem

This topic is 2808 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm feeling really stupid right now, but anyway; I'm making a game in XNA and it's going pretty well, but the way I was doing movement was causing a strange problem of things 'falling';
(velocity, position and acceleration are all vector2s)

position += velocity * (float)gameTime.ElapsedGameTime.TotalSeconds; velocity += acceleration * (float)gameTime.ElapsedGameTime.TotalSeconds;

i figured out that this was because i wasn't normalising and fixed it by doing this...

position += entityMovement.entityVelocity * (float)gameTime.ElapsedGameTime.TotalSeconds; velocity += normalisedAcceleration * (float)gameTime.ElapsedGameTime.TotalSeconds;

Or at least i thought it did, it worked when i did it for bullets the player has fired, but when i put the same code for the player and enemies to use it they just move incredibly slowly, I realised it's because the bullets have a pretty high initial velocity whereas the enemies and player have no initial velocity and that i should probably not be normalising the acceleration...but I can't figure out any other way to do it, can someone please explain to me what it is I should be doing?
I should be normalising just the direction or something?

Thanks for any help.

##### Share on other sites
What are you doing, exactly, when you normalize? Are you properly converting the units the objects velocity/acceleration uses to screen units (pixels)? I'll just assume it

I don't know why you would need to normalize anything. You should just be able to add the velocity*TimeSinceLastMovement to the location vector, and you'd be good.
pixels/time * time = pixels (location) changed during the elapsed time

For Acceleration, it should be the same, but adding it to velocity.
pixels/(time^2) * time = pixels/time (velocity) changed during the elapsed time

Just make sure your units are right, and the time you're giving it is the time since you last called. I assume all these values are using floats (or doubles), since you don't want to lose precision by using ints.

##### Share on other sites
Why don't you try to just modify velocity with the deltatime. That should give you the correct velocity according to your framerate assuming you got all other conversion units right.

##### Share on other sites

What are you doing, exactly, when you normalize? Are you properly converting the units the objects velocity/acceleration uses to screen units (pixels)? I'll just assume it

I don't know why you would need to normalize anything. You should just be able to add the velocity*TimeSinceLastMovement to the location vector, and you'd be good.
pixels/time * time = pixels (location) changed during the elapsed time

For Acceleration, it should be the same, but adding it to velocity.
pixels/(time^2) * time = pixels/time (velocity) changed during the elapsed time

Just make sure your units are right, and the time you're giving it is the time since you last called. I assume all these values are using floats (or doubles), since you don't want to lose precision by using ints.

What do you mean by pixels in those lines of code? Screen coordinates traveled? or just literally the total number of pixels on the screen (xSize*ySize)?

##### Share on other sites

[quote name='BeerNutts' timestamp='1328994114' post='4912052']
What are you doing, exactly, when you normalize? Are you properly converting the units the objects velocity/acceleration uses to screen units (pixels)? I'll just assume it

I don't know why you would need to normalize anything. You should just be able to add the velocity*TimeSinceLastMovement to the location vector, and you'd be good.
pixels/time * time = pixels (location) changed during the elapsed time

For Acceleration, it should be the same, but adding it to velocity.
pixels/(time^2) * time = pixels/time (velocity) changed during the elapsed time

Just make sure your units are right, and the time you're giving it is the time since you last called. I assume all these values are using floats (or doubles), since you don't want to lose precision by using ints.

What do you mean by pixels in those lines of code? Screen coordinates traveled? or just literally the total number of pixels on the screen (xSize*ySize)?
[/quote]

I said pixels, assuming it was the unit of measure you were using for your world coordinates. If the object was on the screen, then, yes, it would be screen coordinates traveled. It wouldn't matter what the screen size was (in resolution) if you were using "pixel" as your world coords.

It could be some arbitrary world coordinates that you are using, but I was just using "pixels" as an example.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 11
• 15
• 21
• 26
• 11