Bullet gravity/angle/trajectory

I’m thinking about implementing something like bullet physics into my game or even for things like rockets and was wondering how I would start with this. Off the top of my head I believe I will need the following things:

Math.atan2 for the angle to the mouse location
Gravity
Speed of the bullet
Velocity

My initial thoughts tell me that i’ll need to first get the angle to the mouse location to fire the bullet at. Then velocity will be effected by gravity, pulling the bullet down towards to floor while also making sure to use the speed of the bullet. Am I missing anything? I’d ideally like to try and code it myself as I think i’ll learn a lot better and be able to implement my own versions depending on my need when and where :slight_smile:

No need for angles, they only ruin your day.

Projectile(s) have:
Position
Velocity
Force [applied] + Mass (or Acceleration)

Instead of an angle to the mouse, just get the direction vector: normalize(mousePosition - bulletStartPosition) aka the common pattern final - initial = change and multiply it by whatever speed you want the bullet to fly at (a scalar value).

Gravity is either applied as an acceleration vector or a force vector via newton’s 2nd law. (force = mass of object * acceleration due to gravity)

Okay… I think I understand :stuck_out_tongue: I have the first part done as I work with projectiles all the time xD just gotta do some digging and get this gravity working!

EDIT: Okay so I have this code:


velocity.y -= GRAVITY;
		
xPos += direction.x * SPEED;
yPos += (direction.y * SPEED) + velocity.y;

It does exactly what I want which is great and is actually annoying because it’s what I had before but my speed constant was giving a weird result. Is this the right way to go about it?

Heed this advice, this is good advice.

Angles are tempting but vectors will be so much easier to work with.