|
| 05 Aug 2014 11:28 PM |
I'd like to know how I'd go about in having a brick rotate a maximum of 90 degrees as you walk closer or further away from a brick in the center of 100 stud radius. This may sound hard to understand but, imagine this.
A brick a position 0,0,0 in the middle of a 100 stud diameter. A brick that turns a certain amount of degrees as you head from negative position to positive position. When you walk across the entire 100 degrees, it will have rotated 90 degrees in total and cannot rotate anymore that way unless you walk back.
Anyone need clarification? |
|
|
| Report Abuse |
|
|
|
| 05 Aug 2014 11:30 PM |
| This is easy to understand. |
|
|
| Report Abuse |
|
|
2eggnog
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 1351 |
|
|
| 05 Aug 2014 11:33 PM |
| I understand what you mean, and I could prepare an explanation. Give me a couple minutes. |
|
|
| Report Abuse |
|
|
|
| 05 Aug 2014 11:36 PM |
No this is a relatively simple idea.
First we need something to measure the amount of degrees needed for every stud upon rotation:
local deg=100/90
now we need a function to get the closest player.
function getPlayerInRadius() local closest for i,v in pairs(game.Players:GetChildren())do if v.Character~=nil and v.Character:FindFirstChild"Torso"~=nil and (Part.Position-v.Character.Torso.Position).magnitude<=100 and (closest==nil or Part.Position-v.Character.Torso.Position).magnitude<=Part.Position-closest.Character.Torso.Position).magnitude) then closest=v end end return closest end
now we need something to constantly update the rotation:
while wait()do Part.CFrame=Part.CFrame*CFrame.Angles(0,0,math.rad(deg)*(getPlayerInRadius()~=nil and (Part.Position-getPlayerInRadius().Character.Torso.Position).magnitude or 0)) end |
|
|
| Report Abuse |
|
|
2eggnog
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 1351 |
|
|
| 05 Aug 2014 11:37 PM |
| Just so I understand, the rotation of the outer part depends on the distance the character is from the center? |
|
|
| Report Abuse |
|
|
2eggnog
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 1351 |
|
|
| 05 Aug 2014 11:38 PM |
| Nevermind, looks like TeddyBauer got it. |
|
|
| Report Abuse |
|
|
|
| 05 Aug 2014 11:39 PM |
| *Raises hand to the sky, puts other hand on the hip, [waits 10 seconds] [looks at watch] then mothership beams me up* |
|
|
| Report Abuse |
|
|
| |
|
|
| 05 Aug 2014 11:52 PM |
I have a question. How do I just put the value of a brick's CFrame.Angles without setting them higher?
So, not this,
brick.CFrame * CFrame.Angles(0,0,math.rad(30))
but where I just say that the brick's CFrame is the same but it's Angles is math.rad(30), not incremented by that. |
|
|
| Report Abuse |
|
|
2eggnog
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 1351 |
|
|
| 05 Aug 2014 11:58 PM |
brick.CFrame = CFrame.new(brick.CFrame.p) * CFrame.Angles(0,0,math.rad(30))
CFrame.new(brick.CFrame.p) returns a CFrame in the same position, but with no rotation. The second part simply applies the rotation. |
|
|
| Report Abuse |
|
|