I'd like to roll a sphere around a room freely, but I'm really not sure how to. The idea is for it to quickly roll around randomly, and, upon hitting a wall, bounce to another direction. To start I tried to just change the CFrame, but this doesn't seem to work properly - since it just goes it just gets more and more teleported to only one direction:
-- NOTE: This script is placed as a direct child of said sphere while script.Disabled==false do script.Parent.CFrame = CFrame.new(script.Parent.CFrame.X+math.random(1,5),script.Parent.CFrame.Y,script.Parent.CFrame.Z+math.random(1,5)) wait(.2) end
If you know how to help, please do so. Also, if this doesn't comply ScriptingHelper's rules, please forgive me - I wasn't sure if this is considered a request.
Thanks!
Okay Since you're using CFrame it will cause the sphere to teleport. Using CFrame Ignores physics Completely. So you should Use BodyObjects: BodyGyro,BodyPosition,BodyAngularVelocity. For this case you would use BodyAngularVelocity.
Simply Insert BodyAngularVelocity into the Sphere you want to roll freely. Next, since you want it to bounce off of walls. Name the bricks "Wall" , this lets the sphere know that you want the sphere to bounce off of that wall.
here's the script:
--VV This will get the sphere to move on its own.Keep this line. script.Parent.BodyAngularVelocity.AngularVelocity = Vector3.new(math.random(-20,20),0,math.random(-20,20)) script.Parent.Touched:connect(function(hit) if hit.Name == "Wall" then script.Parent.BodyAngularVelocity.AngularVelocity = Vector3.new(math.random(-20,20),0,math.random(-20,20)) if script.Parent.BodyAngularVelocity.AngularVelocity == Vector3.new(0,0,0) then script.Parent.BodyAngularVelocity.AngularVelocity = Vector3.new(math.random(-20,20),0,math.random(-20,20)) end end end)
Ta-Da , I've done it myself, and it works completely fine Hope I Helped.