|
| 23 May 2013 03:55 PM |
| Hello! I can't figure how to point a part's front face towards a location using cframe's rotation. Can my fellow scripters help me? |
|
|
| Report Abuse |
|
|
|
| 23 May 2013 03:57 PM |
| What are you wanting it to point towards? |
|
|
| Report Abuse |
|
|
MrNicNac
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 26567 |
|
|
| 23 May 2013 03:58 PM |
"using CFrame's rotation"
I'm going to assume you don't mean:
CFrame.new(Part.Position, lookAt)
If it is, great, if not, then I can help with any matrix math you might want. |
|
|
| Report Abuse |
|
|
ForceSky
|
  |
| Joined: 30 Jul 2012 |
| Total Posts: 2379 |
|
| |
|
|
| 23 May 2013 04:00 PM |
I'm basically just trying to emulate how the bodygyro object works, but for only a breif second, and instantaneously.
I usually don't play around much with CFrames but I'll try your tidbit of code.
For The Curious: I'm trying to aim a rocket. |
|
|
| Report Abuse |
|
|
|
| 23 May 2013 04:00 PM |
I'm going to make a general example for you;
This points the brick to the location of the nearest player's torso, but only within a set distance. It can be edited to point wherever you wish if it's what you're looking for.
function findTorso(pos) local torso = nil local dist = 1000 local child = workspace:children() for i=1, #child do if child[i].className == "Model" then local h = child[i]:findFirstChild("Humanoid") if h ~= nil then local check = child[i]:findFirstChild("Torso") if check ~= nil then if (check.Position - pos).magnitude < dist then torso = check dist = (check.Position - pos).magnitude end end end end end return torso end
while true do wait() local torso = findTorso(script.Parent.Position) if torso ~= nil then script.Parent.CFrame = CFrame.new(script.Parent.Position, torso.Position) end end
|
|
|
| Report Abuse |
|
|
|
| 23 May 2013 04:02 PM |
Solved it.
Thanks for helping guys.
I was doing what MrNic posted originally, but I kept adding the part's CFrame to it's cframe.
|
|
|
| Report Abuse |
|
|