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

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

Asked by 8 years ago

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.

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. captiongoosebut 19 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

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

0
This should be in a comment. Only answer if you're giving an answer, please. Perci1 4988 — 8y
0
Perci1, he doesn't have enough reputations. Don't downvote this. rexbit 707 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

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!

Answer this question