Hello this is my first post, i nead some help.
I want to build simple NPC car (NPC ride it player cant) with stearing to points.
One wheel at back is power wheel, foward wheels are connected with servos to car,
i nead to get them to some angle to move to points (like real car).
Dont wory i tested model while manual steering it and it mowed where i wanted.
So far i have made car steer with no oscilations and that kind of garbage bugs,
but i cant get it to right angle to steer.
Script that i used:
destination = route[“1”]
local dy = y2 - y1
local dz = z2 - z1
local angle =math.deg( math.atan2(dy, dz))
Script works well to some point but then i get this:
If you can help, please help me…
Sorry for broken English…
August 2, 2020, 6:48pm
local unit = (destination.Position - thisCar.Position).Unit
local angle = math.atan2(unit.x, unit.z) -- (might end up being unit.z, unit.x)
HingleConstraint.TargetAngle = angle
I got mixed results…
When is going towards X cordinate line, it works
But when it goes to Z…
i tried to flip math.atan2(unit.X, unit.Z), but nothing happend…
and i tried this angle=math.deg( math.atan2(unit.X, unit.Z) ) but i got…
it going around…
I will give ya car model if you want to test it or just take it
test car model.rbxm (1.4 MB)
August 3, 2020, 6:21am
ok, im gonna check your code!
August 3, 2020, 6:51am
It is hard…
It may take time
No problem, its not something extra important or something like that, take your time and go easy
Your code (with
math.deg) inherently is a good idea, but you’re calculating the angle from only positions, which realistically does not work, since if the car is rotated, the target angle has to adjust accordingly. This is why the car points into the right direction at the very beginning, but doesn’t update its wheels during motion. To “fix” your current solution, just adjust the angle according to the car orientation.
angle = math.deg(math.atan2(unit.X, unit.Z)) - thisCar.Orientation.Y+180
August 3, 2020, 7:44am
I maked auto pilot using
test car model.rbxm (2.9 KB)
August 3, 2020, 10:49am
I was stupid to forget that… anyway thanks man
August 3, 2020, 10:50am
did you send right model? i get from your model just route model?
August 3, 2020, 10:52am
Thank you all for your hard work, if i can somehow help you, tell me!
August 3, 2020, 12:06pm
Woops, i send wrong file…
test car model.rbxl (101.9 KB)
This is correct one
August 3, 2020, 12:39pm
Wow this looks nice,
few seconds later car dies i have to modify this, thank you anyway
August 3, 2020, 12:41pm
You can delete
to protect car lol
August 3, 2020, 12:44pm
I know but it looked funny…
Just wroom to last point and then brek
August 3, 2020, 12:49pm
may i also ask what effect does
#destination have on destination value?
(what # does?)
August 3, 2020, 12:51pm
#destination:GetTouchingParts() returns a number.
This will return the number of parts the destination is touching.
August 3, 2020, 12:54pm
i did small modifcation on script so it dont destroys parts on contact, destroys them on distance, i will use this with path finding service
if (destination.Position-script.Parent.Center.Position).magnitude <= 1 then
August 3, 2020, 12:57pm
I had no such idea!
(30 characters bruhhhhh)