generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Can't get parts to rotate with model

Previous Thread :: Next Thread 
RaichuaTheFurry is online. RaichuaTheFurry
Joined: 20 Dec 2016
Total Posts: 62
23 Nov 2017 06:48 PM
I'm trying to write a script where a model, with the primary part anchored, always points toward my head, but when I try to alter the orientation of the primary part, the welds break on the model. I hear changing the CFrame can fix this, but I don't know how to change the orientation by CFrame.

Here is the script:

char = game.Workspace:WaitForChild("RaichuaTheFurry")
axis = script.Parent.Axis

while wait() do
local charPosX, charPosY, charPosZ = char.Head.Position.X, char.Head.Position.Y, char.Head.Position.Z
local zyAdj = charPosZ - axis.Position.Z
local xOpp, yOpp = charPosX - axis.Position.X, charPosY - axis.Position.Y
local xHyp_yAdj = math.sqrt(zyAdj^2 + xOpp^2)
if zyAdj < 0 then
xHyp_yAdj = -xHyp_yAdj
end
local xATanDeg = (180 * (math.atan(xOpp / zyAdj))) / math.pi
local yATanDeg = (180 * (math.atan(yOpp / xHyp_yAdj))) / math.pi
if zyAdj ~= 0 then
axis.Orientation = Vector3.new(axis.Orientation.X, xATanDeg, axis.Orientation.Z)
if yOpp ~= 0 then
axis.Orientation = Vector3.new(-yATanDeg, axis.Orientation.Y, axis.Orientation.Z)
else
axis.Orientation = Vector3.new(0, axis.Orientation.Y, axis.Orientation.Z)
end
else
if yOpp > 0 then
axis.Orientation = Vector3.new(-90, axis.Orientation.Y, axis.Orientation.Z)
elseif yOpp < 0 then
axis.Orientation = Vector3.new(90, axis.Orientation.Y, axis.Orientation.Z)
else
axis.Orientation = Vector3.new(0, axis.Orientation.Y, axis.Orientation.Z)
end
end
end
Report Abuse
nofascistsaloudxD is not online. nofascistsaloudxD
Joined: 02 Sep 2015
Total Posts: 408
23 Nov 2017 06:52 PM
You can changed the orientation of a part through CFrame in multiple ways. One is by defining where you want the part to face by doing this: part1.CFrame = CFrame.new(part1.Position, part2.Position) --This will make part1 face part2 another way to go about this is by: part1.CFrame = part1.CFrame * CFrame.Angles(math.rad(15),math.rad(15),math.rad(15)) -- This will make ##### #### ## ##### and rotate to the radians given.
Report Abuse
RaichuaTheFurry is online. RaichuaTheFurry
Joined: 20 Dec 2016
Total Posts: 62
23 Nov 2017 06:56 PM
So I basically had to relearn basic trig today just to find out that there's already a built-in pointing function? :P
Report Abuse
nofascistsaloudxD is not online. nofascistsaloudxD
Joined: 02 Sep 2015
Total Posts: 408
23 Nov 2017 06:56 PM
XD XD yeah....
Report Abuse
RaichuaTheFurry is online. RaichuaTheFurry
Joined: 20 Dec 2016
Total Posts: 62
23 Nov 2017 06:57 PM
Lol, whoops
Report Abuse
nofascistsaloudxD is not online. nofascistsaloudxD
Joined: 02 Sep 2015
Total Posts: 408
23 Nov 2017 06:57 PM
Nice math, though... Much better than I could do.. Or event think of XD
Report Abuse
RaichuaTheFurry is online. RaichuaTheFurry
Joined: 20 Dec 2016
Total Posts: 62
23 Nov 2017 07:00 PM
Thx m8
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image