Right now I have an AI hit and apply a velocity where the velocity is a .Unit from the AI’s torso and the player’s torso + their movedirection. It always overshoots it’s target or nails it, there is no in between.
What other system or math algorithm I could use to make the AI hit it’s target frequently?
then the function (which i can’t really post, it does a lot of if statements just to get to this main part)
calculates the velocity with this:
local bv = Instance.new('BodyVelocity')
bv.Name = 'HitVelocity'
bv.Parent = hrp
bv.P = 5000
bv.MaxForce = Vector3.new(math.huge,0,math.huge)
local function hitvel()
if power <= 25 then
bv.Velocity = (position-char.HumanoidRootPart.Position).Unit*(power*1.4)
else
bv.Velocity = (position-char.HumanoidRootPart.Position).Unit*(power*1.2)
end
end
hitvel()
game:GetService("Debris"):AddItem(bv,.5)
(power being on a scale of 0-50 where it’s calculated as distance from the player*1.5)
This indicates that the enemy’s mouse doesn’t account for the humanoid’s current velocity.
And I also realize the velocity function that you made isn’t constant and does an arbritary calculation of:
Overall, the targeting system you made doesn’t account for the physics required to hit a leading target. Seems like you will need to study target leading which will require lots of math. Here is a good website to start with:
I tried that but if you press A and then stop moving, the AI will entirely fly next to you because you velocity for that split second is Vector3.new(32,0,0) then it isn’t.
I was reading this but I’ve been having trouble calculating the angles due to the projectile(the player moving) is not static, it is sporadic and changes every millisecond where character Velocity is measured in Studs/Per Second. I couldn’t really find an quality way to apply this.
It might be a problem with Roblox humanoid being a pain to shoot and having fast acceleration and that the projectile speed is too slow to intercept. Moreover, by the time the projectile is fired the player can react just like you did and undo all the hard work the AI calculation has done:
Basically you need near hitscan levels of speed to hit default humanoid characters. So here are the possible solutions:
Code a new movement system that makes humanoids acceleration in every slower
Make bullet velocity very high
Then the AI would be able to hit more consistently.
Alternatively, you can use this neural network library to do machine learning and make the AI “Predict” where the player is going.
What I did now is took the velocity and multiplied it by a percentage based on calculating time it’d take for the AI to fly over to the target and hit him. It’s a pain but it’s whatever, your page explaining projectile interception helped wonders though, so thanks again for that!