Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Roll sphere freely?

Asked by
RafDev 109
9 years ago

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!

0
Try making conveyor belt bricks near the walls and check on touch if the part got a humanoid or not. haloelite27 25 — 9y
0
Perhaps use BodyObjects? Perci1 4988 — 9y
0
Yes, it may works. haloelite27 25 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

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.

0
Sphere doesn't move at all, just stays there, even though its unanchored. No errors. RafDev 109 — 9y
1
Make sure it isn't touching Anything. Since Roblox implemented the "Auto-Weld" feature. Make sure its floating about 1 stud high above the floor. GeezuzFusion 200 — 9y
0
Works, thanks! RafDev 109 — 9y
Ad

Answer this question