Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Roll sphere freely?

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!

3 comments

0

Try making conveyor belt bricks near the walls and check on touch if the part got a humanoid or not.

0

Perhaps use BodyObjects?

0

Yes, it may works.

1 answer

✓ Accepted answer

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.

3 comments

0

Sphere doesn't move at all, just stays there, even though its unanchored. No errors.

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.

0

Works, thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.