Ah, my mistake! I misread your forum post, I made a correction to my response, and as well included the AI Vehicle demo by ScriptOn. My apologies!
It’s not moving now. Cries
Wrong Base?
local Service = game:GetService(“RunService”)
local Rotate = script.Parent.Weapon.Rotater.Hinge
local Tilt = script.Parent.Weapon.Bar.Hinge
Service.Stepped:Connect(function()
local Target = script.Parent.Aiming.Value
if Target ~= nil then
local localizedTarget = script.Parent.Base.CFrame:PointToObjectSpace(Target.Head.Position)
local yaw = math.atan2(-localizedTarget.X, -localizedTarget.Z)
local pitch = math.atan2(localizedTarget.Y, math.sqrt((localizedTarget.X ^ 2) + (localizedTarget.Z ^ 2)))
Rotate.TargetAngle = math.deg(yaw)
Rotate.TargetAngle = math.deg(pitch)
end
end)
You’re setting the same hinge for both angles.
Making an AI for this doesn’t need to be super complicated, it’s just a simple algorithim, that checks if the player is in range, and if so check if there is something in the way of the ray that it’s firing, and if not shoot.
I am not very good with AIs but I can suggest;
There is a tutorial on youtube called
“Tank AI” by Y3llow Mustang. He is a very good scripter.
Video link.
Ahhhh, It’s not aiming right.
Oh I use another way to aim the gun right.
I used bodygyro to aim it it.
It worked pretty well XD.