AI Car doesn't drive straight

Hello!

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

The car chassis is made from constraints.

Video:
Roblox (gyazo.com)

(this is also my first post on the devForum)

1 Like

Have you added any dampning to the steering yet?

I don’t think that will do anything, because when i first start the game, the car drives PERFECTLY straight. No wobbling.

What is the instance hireachy of your car?

First time ever hearing that word, but i think this is what you want.

Welcome to the forums!

So when you first start the game, does the AI car work as intended? When does it start to wobble and go crazy?

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

exactly, thats what you call an NPC,
so yeah do try a straight road

I planned to make the cars dissapear when they go too far from the nearest player and spawn back driving toward the player.

Ill remove the bodywork on the car aswell.

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

Steering system:

I think a better word to describe the driving is swerving. (English isnt my native language)
https://gyazo.com/5f5c24c7614cb6012de5d031b9f3e6d9

The white one is owned by server and green owned by player.

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

This is in a RunService.Heartbeat function

1 Like

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