Here is a screenshot of what I’m trying to accomplish:

I do not want to use the built in unity movetowards or anything like that. this is a pure c# formula question. How would I detect this without using help from unity. The reason why is because unity turns the bullets with movetowards which is not what I want…the bullet needs to remain straight and impact the target’s position it’s moving towards.

It is a prediction formula I’m looking for and it’s pretty basic but I’m so use to just cheating and using stuff like vector3.movetowards that I’m not really sure how to do this.

What I’ve figured out so far is I will need to do something like this…

but what’s the rest of the formula? how do I do the rest? bulletspeed would be used somehow in this right?
I never get any answers on unity answers so figured it’d ask here lol…

You’re mixing up an algorithm to move an object in a straight line, versus an algorithm to calculate where 2 lines would intersect.

If you want the second, well you need to start with what unknown variable are you calculating for, and what values are known and/or constants.

For example, the thing you’re trying to shoot is moving from some position in some direction and some speed. These are knowns that can’t be changed.

The projectile you shoot is probably also a constant, and therefore known.

Where as the position you shoot from, the speed you can move to that position at, the time you shoot at, and the direction you shoot in are all unknowns.

And the thing is, the more unknowns, the harder it is to calculate, since there can be an infinite number of answers to resolve a system with 2 or more unknowns. So usually you calculate with 1 unknown… just like a sniper will lay down and not move and reduce all unknowns (wind velocity, etc) and then just shoot in a specific direction (1 variable) to increase accuracy of strike.

Well you need to do the same thing. You need to decide what unknowns you’ll force to knowns (stop moving and stand still to shoot), to reduce unknowns to 1 or 2.

And even then there’s no guarantee. You could stop movement and end up behind a wall, and therefore unable to shoot.

for the target the knowns are:
velocity & position
projectile knowns are:
speed
player knowns are:
velocity & position
so your saying I would have to do to many calculations with this much information and there is no real simple way to do it?
Walls would not matter in this equation btw that whole thing can be ignored.
Think of it as an automated targeting asteroids game.

Ah I’ve always thought of trajectory as gravity being involved guess I’ll look into it. Thing is, it does work if the ship stays still now which makes me think it is just an issue with that interception math when the player is moving.

EDIT: after just reading the very start of what james posted:
"the ballistic trajectory of a projectile is the path that a thrown or launched projectile or missile will take under the action of gravity"
it does involve gravity if you go into trajectory?

Ok. So I assumed that you are using a rigidbody driven projectile. Instantiate, AddForce in correct direction, let it fly. Is this correct? Or are you doing your projectile movement some other way?

The first algorithm doesn’t care about gravity. Its solely about predicting a future position based on projectile velocity and target velocity. It is accurate assuming the target follows a constant vector/speed (straight line). If the target is say flying in a circle, it will likely miss. Not much you can do about that.

The second algorithm is what accounts for bullet drop. It will calculate how much additional angle you need to add based on gravity, velocity, and distance. If your projectiles are not using gravity, you wont need this.

Also make sure your projectile drag settings are 0. Any drag will change the velocity making your projectiles miss. You can account for that with extra algorithms, but tbh, its not worth the effort/calculate. Just turn off drag. Make your life easy.

nah It shoots in a direction based on this vector3. y is not used since it’s 2d.

The easiest way I can think of to describe this is if you want AI to try and shoot ahead of you if you try to strafe left or right. The AI needs to predict where you are moving and how far ahead they predict essentially determines the AI’s accuracy.

What you are talking about is impossible. You cant hit an unpredictable target. If the player moves left/right constantly with no consistency there is no way of accurately predicting where the player will be.

What sort of distances are we talking about? If its 2d, you can probably get rid of the prediction and use angle of reach solely if the distances are close (less than 100 units). This is dependent on the velocity of your projectile. If its slow, you have no chance of prediction.