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

How to keep object from changing position when moving over other objects?

I've noticed this when scripting objects to move/rotate (In this instance rotate)

I've made a fan and wanted it to slowly rotate so I made the following script:

local rotate = 0

while true do
	wait()
	rotate = rotate + 1
	script.Parent.Rotation = Vector3.new(0,0,rotate)
end

So it rotates the way it is supposed to, but one issue. The blades of the fan do not stay where I have them put. The way I fixed this was by just placing the fan blade part right in a position where the other piece of fan is not inside of it, but my question is basically; is there a way to get an object to ignore this and just stay in the same position while moving/rotating? And yes, the brick is anchored.

1 comment

0

Forgot to mention: whenever the character runs directly under the fan while it is spinning it moves upwards to where it isn't touching the player, but is no longer attached the the fan and the blades are just floating there.

2 answers

Could you maybe upload a picture to gyazo, or imgur and send us the link so we can see what you mean?

2 comments

0

This should be in a comment. Only answer if you're giving an answer, please.

0

Perci1, he doesn't have enough reputations. Don't downvote this.

You would use CFrame

CFrame basically sets the part where you want it to, but Vector3 make sure it doesn't collide with anything and moves it accordingly.

Because you are using Vector3, the fan moves all over the place when it collides with something because your setting the Vector3 wont allow for that!

All about CFrame

Now, to change rotation in CFrame, you would have to use CFrame.Angles, which works like rotation but uses radians instead of degrees.

Converting radians to degrees is easy, however! Just use math.rad

So, your overall code would look something like this

local rotate=0

while true do
	wait(0.1)
	rotate=rotate+1
	script.Parent.Rotation=script.Parent.CFrame+CFrame.Angles(0,0,math.rad(rotate))
end

Hope this helped!

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