Im currently making a AI car that follows waypoints on the road and ive encountered a little problem.
The car tends to start wobbling all over the road, getting worse over time.
I suspect its something to do with network ownership
When first started the car drives just fine. After around a minute it starts wobbling, getting more intense over time. Sometimes it even flips because the car has a suspesion.
It can’t be the script’s fault, ive looked through it and there doesn’t seem to be any memory leaks.
The car also stutters whenever i get close to it or go further away from it.
stuttering might be due to network ownership, you might have to write an automatic network ownership system,
after a minute wobbling? are you sure the nodes are not the fault? or when nodes count as reached, or maybe its what your ai learns, you said you wrote an Ai, or do you mean NPC
Yes, the stuttering can’t be anything else other than network ownership. Ive tried to force the network owner to the server, but i don’t think thats possible.
Setting it to the player doesn’t fix stuttering.
AI might be a bit misleading… the car drives from one waypoint position to the other by changing the servo rotation. Ill make it drive on a different path and see if it has an effect.
exactly, forcing network owner to the server is possible by setting it to nil, but that will make your problem so much worse, you need to write a network ownership system that gives it to the closest player, why simulate the ai when hes far away anyway
if it would still stutter afterwards, can it be too many parts? try disabling shadows on the complex sections of the car, only shadow the wheels and some thing on the ground of the car
i wasnt saying disappear, that could get annoying unless its not a racing game youre making then thatd be better than setting their networkship to nil when too far away, and when close to a player, amke sure it takes the closest player as the network owner
I made 2 cars drive at the same time, one of them had server as network owner, and the other one as the player.
The server one drove straight with no stuttering, the one with network owner as the player was wobbling.
the only sensical explanation i could have for that would be more precise physics calculation, when you have more than 4 cars you will get hella problems on the server physics running all of them on the server, i have experience.
so basically you should check their wheels size, positioning and the springs attached, also i dont know what you mean by wobbling, not for sure, can you send me a video
that just looks like steering a little too far to me, make sure the steering is more instant and the steering angle is calculated properly, and from the correct origin position (assuming youre using dot product or something simlar)
This piece of code was made quite some time ago… I don’t think i even came up with this myself.
local target = (CurrentWaypoint.CFrame + (car.CarMain.CFrame.RightVector*6)).Position --im adding 6 studs because i want to have them drive in a lane
local myPos = script.Parent.Position
local rot = math.atan2(target.Z-myPos.Z, target.X-myPos.X)
local desiredAngle = math.deg(rot) + script.Parent.Orientation.Y + 90
if desiredAngle > 180 then
desiredAngle = -(360 - desiredAngle)
elseif desiredAngle <-180 then
desiredAngle = 360 + desiredAngle
end
if desiredAngle > 45 then
desiredAngle = 45
elseif desiredAngle < -45 then
desiredAngle = -45
end
RightSteering.TargetAngle = script.Steerangle.Value
LeftSteering.TargetAngle = script.Steerangle.Value
i have no idea how that works, i personally used DotProduct from an attachment that is in the center of the front wheels, dot producting to the next waypoint and setting the car’s VehicleSeat to the resulted dot product by calling the function i wrote, and then in the chassis setting the maximum steering angle times steerfloat, and something with steering speed but i dont remember what that was
Good luck! probably much easier to understand than those mathematics you have to directly understand, good luck and make sure to document your code for your own good, your car system will get complex