Skip to main content
Share Your Experience: Take the 2024 Developer Survey
12 votes
Accepted

Projectile Aim Prediction with Acceleration

To make things a little simpler, let's work within the inertial frame of our launcher. That means our projectile will be firing from the point (0, 0, 0). (You can subtract any arbitrary firing ...
DMGregory's user avatar
  • 135k
12 votes
Accepted

Why aren't game bullets implemented as if they were real bullets?

The main problem is tunneling. Game physics engines typically use discrete collisions. That means they advance all the bodies by one short time step, then check if they're intersecting, and handle ...
DMGregory's user avatar
  • 135k
10 votes
Accepted

Guided Missile with Constant Time

The edit is reassuring. :) Okay, here's a straightforward update loop... Assuming when we fire the missile we initialize remainingFlightTime = 5f then... ...
DMGregory's user avatar
  • 135k
6 votes
Accepted

How to create a projectile motion of a cannonball in top down view?

From wikipedia: $$d=\frac{v_0^2}{g}sin(2\theta)$$ When you reverse the formula to find the angle from the distance and initial speed, it becomes: $$\eqalign{ d&=\frac{v_0^2}{g}sin(2\theta) \\ ...
starikcetin's user avatar
  • 5,275
5 votes
Accepted

How can I recreate the movement of arrow in air?

You need a bit of physics, and a touch of calculus. Lets assign P as the point of the arrow, L as the length of the arrow, and Q as the tail of the arrow. You launch the arrow at an initial velocity ...
Mike White's user avatar
5 votes

What is a "Projectile"?

From dictionary.com: projectile[ pruh-jek-til, -tahyl ] noun an object fired from a gun with an explosive propelling charge, such as a bullet, shell, rocket, or grenade. a body ...
Philipp's user avatar
  • 120k
4 votes
Accepted

Javelin throw projectile motion

To align a javelin, you should properly compute all forces. The reason that a javelin can orient itself into its path, is because of air drag. Note that the drag is not always asymmetric enough to ...
Bram's user avatar
  • 3,719
3 votes

Shooting projectiles towards mouse position in Unity 2D

Your problem here is two fold: First, when you spawn an object, that should be the last the current script interacts with it. From that point forward, the new object should control its own behavior. ...
Stephan's user avatar
  • 1,728
3 votes

Elastic Circle-Circle collision detection and response / Slime Volleyball physics

Basically, you want to implement circle-cirle collision detection and response. I consider your character a static object and the ball a dynamic object. I do this because it makes everything a lot ...
Bálint's user avatar
  • 14.9k
3 votes
Accepted

Scrolling background after firing projectile

Declare an x value for your camera, and then offset everything (projectile, scenery, etc.) by that camera's X. For example, If I want my camera to be 500 pixels to the right, but projectile is 600 ...
tyjkenn's user avatar
  • 2,586
3 votes

Javelin throw projectile motion

Have you ever thrown a javelin straight up? It does actually rotate quickly on top, because the pointy end is heavier. But it does so not when it reaches the top but after the velocity changes to move ...
Josh Vander Hook's user avatar
3 votes
Accepted

Find projectile initial velocity, and air time, given projectile elevation, distance, angle

If your projectile is fired on a 45 degree angle, that's: $$ \vec v = (c, c)$$ ...for some scalar component \$c\$. Gravity doesn't affect the horizontal axis, so the time it takes this projectile to ...
DMGregory's user avatar
  • 135k
3 votes
Accepted

How to make mouse pointer be the vertex of a drawn parabola when estimating the trajectory of a projectile?

I think we can do this more simply. This demo uses about 80 lines of code (the interesting ones being just the dozen below), instead of over 300, with no angles/trigonometry functions needed: At the ...
DMGregory's user avatar
  • 135k
2 votes

How can I launch a GameObject at a target if I am given everything except for its launch angle?

I modified DMGregory and Evorlor's solution a bit as I wanted a 3D arc and wanted to be able to apply a minimum speed if the provided speed wouldn't reach. ...
Tim's user avatar
  • 21
2 votes
Accepted

Calculate initial velocity for trajectory given duration, launch angle, and distance

Note: the situation you describe (angle, start, end, and time of flight) is overdetermined. For many (most) inputs, there will be no solution that simultaneously satisfies all of these constraints. (...
DMGregory's user avatar
  • 135k
2 votes
Accepted

Required initial velocity (fixed launch angle) for projectile to hit a target

[Reposted as an answer, at the asker's request] turretAngle is in degrees, so you need to convert it to radians before passing it to ...
Victor T.'s user avatar
  • 1,381
2 votes

Why aren't game bullets implemented as if they were real bullets?

For most games it doesn't make a difference. Take the Counter Strike series, for example. It simulates firearms combat on rather short distances. On the distances where the average CS shootout takes ...
Philipp's user avatar
  • 120k
2 votes
Accepted

Rifle bullets/projectiles in Unity, raycasting or rigidbody?

A simple raycasting would be instantaneous. This is usually referred to as Hitscan. A simple example would be in Doom, some weapons and enemies hit immediately while others can be dodged after they ...
CLo's user avatar
  • 1,330
2 votes

Pushing Rigidbody forward doesn't go straight

Those calculations you made are taking into account a direction that is forward of the camera center. But you are instanciating the grenade in an arbitrary transform called ShootPoint. so how to ...
Omar Guendeli's user avatar
2 votes
Accepted

how to calculate initial Y velocity required to reach target?

You are going to need to use the Equations of Motion. This is because the velocity is not constant over the time frame. You cannot calculate distance traveled by velocity and time alone. One way to ...
Jay's user avatar
  • 810
2 votes

Javelin throw projectile motion

maybe you should position the javelin in such a way, that the 'nose' of the javelin is where the curve is, not in the middle, that way it might look a little 'more natural'. or you can add a turning ...
DrDragonite's user avatar
2 votes
Accepted

How do I launch a ballistic projectile to hit a moving target, given: launch position & angle, target position & velocity?

I'm assuming that your gravity acts on the vertical axis, and that your launch angle is an altitude (measured vertically from the horizon, so 0° means firing horizontally, and 90° means firing ...
DMGregory's user avatar
  • 135k
2 votes
Accepted

Find the direction a Projectile should be fired from a Moving Object to hit another moving Object?

This is the updated code, with code for handling some edge cases. Also, I made sure the BULLET_SPEED large enough for the Equations to work: ...
Vignesh Gunasekaran's user avatar
2 votes

Emulating 3d trajectory in top-down 2d game?

I created this version which uses a target position and t (time 0-1). I would loop this function in an update function if (t < 1) t would increase by ...
Joel Leonard-Best's user avatar
2 votes
Accepted

How to calculate trajectory on a planet with drag factor

Your approach has good grounds, but there are mistakes in your code. A little theory first: Your simulation needs to use the second law of Newton which gives you the acceleration of the projectile: \$\...
Sacha's user avatar
  • 466
2 votes

When an object is launched off-screen, is there any way to know if it's coming back?

The equation of motion for an object accelerating under constant gravity is: $$\vec p(t) = \vec p_0 + \vec v_0 t + \frac 1 2 \vec a t^2$$ ...where \$t\$ is the number of seconds since you started ...
DMGregory's user avatar
  • 135k
2 votes

How could I simulate projectile collision agaisnt RTS units with primitive colliders?

Like DMGregory said: it's very unlikely Total War is actually simulating physics for all those arrows. There's probably a big separation from the battle simulation and the actual animations in game. ...
Charly's user avatar
  • 742
2 votes
Accepted

How to find the maximum distance a target point can be hit from a launched projectile

Using the code in this answer: ...
DMGregory's user avatar
  • 135k
2 votes
Accepted

Model path of bullet to hit future position of balloon

If I understand correctly, the targets move along a path defined as a series of points. So, effectively, it is moving along a series of straight segments, correct? Thus, you could: Solve the time and ...
Theraot's user avatar
  • 27k
1 vote
Accepted

Pushing Rigidbody forward doesn't go straight

As previously answered. If you spawn your projectile offset from the camera, and shoot it in the direction of a transform attached to the rifle then it won't line up with the camera because the rifle ...
Saevax's user avatar
  • 251

Only top scored, non community-wiki answers of a minimum length are eligible