I am making a car script, but I need to know how to get it to rotate. How can I do this?
Code:
local bodyvelocity = Instance.new("BodyAngularVelocity")
bodyvelocity.Parent = script.Parent
game["Run Service"].Heartbeat:Connect(function()
if script.Parent.Parent.Rotating.Value == true then
if script.Parent.Parent.RotatingDirection.Value == true then
else
end
else
end
end)
firstly, it is game:GetService("RunService)
secondly, heartbeat is an function of client’s rendering. May I ask why exzactly are you doing a thing that is supposed to replicate in a localscript?
i use runservice because it acts like wait() in serverscripts.
my script for the moving uses a similar function, and it is not broken for some reason?
and please, do you have a second reason or just one?
Hmm, sorry I am not the most experienced… I have not seen runservice on server before…
well, since the snippet you provided is mostly empty, did you set the angular velocity constraint right? as in it have a force, and isn’t disabled etc…
Bodyangular velocity is deprecated so that may also be why.
i have set it, my moving script uses bodyangularvelocity, i decided to remove the setting velocity code until i find a workaround, here is where you put the code:
local bodyvelocity = Instance.new("BodyAngularVelocity")
bodyvelocity.Parent = script.Parent
game["Run Service"].Heartbeat:Connect(function()
if script.Parent.Parent.Rotating.Value == true then
if script.Parent.Parent.RotatingDirection.Value == true then
--right
else
--left
end
else
--set it to vector3.new()
end
end)
I don’t understand? How would you expect the bodyvelocity to apply a velocity without you setting the velocity? (why would you remove the setting velocity code?)
i removed the setting code because i was trying to use the rotation property of the chassis
spoiler alert: it didn’t work so well. forgot to remove the local bodyvelocity part though…
Correctly me if I am wrong, so you are wanting to directly set the rotation of the part/model?
well you could do thething.CFrame *= CFrame.Angles(0,rotation,0)
if it is a model do
local model = themodel
while true do
if script.Parent.Parent.Rotating.Value == true then
if script.Parent.Parent.RotatingDirection.Value == true then
model:PivotTo(model.PrimaryPart.CFrame * CFrame.Angles(0,0.1,0))
else
model:PivotTo(model.PrimaryPart.CFrame * CFrame.Angles(0,-0.1,0))
end
else
end
wait()
end
Try this you may need to edit to get it to work with your system
local bodyvelocity = Instance.new("BodyAngularVelocity")
bodyvelocity.Parent = script.Parent
game:GetService("RunService").Heartbeat:Connect(function()
if script.Parent.Parent.Rotating.Value == true then
local rotationSpeed = 100 -- Adjust this value to control the speed of rotation
if script.Parent.Parent.RotatingDirection.Value == true then
bodyvelocity.AngularVelocity = Vector3.new(0, rotationSpeed, 0) -- Rotate clockwise
else
bodyvelocity.AngularVelocity = Vector3.new(0, -rotationSpeed, 0) -- Rotate counterclockwise
end
else
bodyvelocity.AngularVelocity = Vector3.new(0, 0, 0) -- Stop rotation when not needed
end
end)
What you are doing would be pretty hard to explain in a forums post. This has a lot to do with the set up as much as the script(s). Best way to go about this would to find a tutorial or head to the toolbox for examples to learn from. A search like: starter car brings up many, with many different ways of going about this.
Here is a few that are pretty easy to understand … (not saying these are the best way, but a good start)
There are many examples, one of the best is Roblox’s new buggy on the new Race template.
This in the end would be a good goal to understand. It’s about as good as it gets.