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: Problem with CFrame

Previous Thread :: Next Thread 
CrowClaws is not online. CrowClaws
Joined: 04 Jul 2010
Total Posts: 4466
26 Apr 2015 02:51 PM
game:GetService('RunService').RenderStepped:connect(function()
local Char = Tool.Parent

if Char:FindFirstChild'Humanoid' then

local Torso = Char['Torso']
local Arm = Char['Right Arm']
local Shoulder = Torso['Right Shoulder']
local Neck = Torso['Neck']

Shoulder.C1 = ((CFrame.new((Shoulder.Part0.CFrame * Shoulder.C0 * CFrame.new(0,-0.5,0.5)).p, Mouse.Hit.p + (Mouse.UnitRay.Direction * 1e10))) * CFrame.fromAxisAngle(Vector3.new(1,0,0), 0)):toObjectSpace(Shoulder.Part0.CFrame * Shoulder.C0)
Neck.C1 = ((CFrame.new((Neck.Part0.CFrame * Neck.C0 * CFrame.new(0,0,.5)).p, Mouse.Hit.p + (Mouse.UnitRay.Direction * 1e10))) * CFrame.fromAxisAngle(Vector3.new(1,0,0), 0)):toObjectSpace(Neck.Part0.CFrame * Neck.C0)
end
end)

So i have this. Works perfectly and all but there are two problems:

1.) The top of the arm ("shoulder") points to Mouse.Hit.p, how would i make it so the "hand" (Bottom surface) Faces Mouse.p

2.)How can I make it so the player can't turn there head all the way around. How would i limit their rotation?
Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
26 Apr 2015 03:12 PM
1. Rotate it by 90 degrees

2. idk but your using a lot of cframe for something I did with like no knowelege of scripting, but your way will probably be better

my old way:

neck.C1 = CFrame.new(torso.Position,mouse.Hit.p) + Vector3.new(0,1,0) -- Could be wrong but this is the basic idea
Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
26 Apr 2015 03:15 PM
with like no knowledge of cframe*

anyway I doubt that is what I had anyway, I think I did :toObjectSpace(torso.CFrame)
Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
26 Apr 2015 03:33 PM
http://www.roblox.com/Forum/ShowPost.aspx?PostID=161001662
Report Abuse
CrowClaws is not online. CrowClaws
Joined: 04 Jul 2010
Total Posts: 4466
26 Apr 2015 03:34 PM
@Cas
This is different :I
Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
26 Apr 2015 03:35 PM
@Crow It fixes issue 1.) The top of the arm ("shoulder") points to Mouse.Hit.p, how would i make it so the "hand" (Bottom surface) Faces Mouse.p
Report Abuse
CrowClaws is not online. CrowClaws
Joined: 04 Jul 2010
Total Posts: 4466
26 Apr 2015 03:44 PM
@Cas

Ah!
I thought you were complaing about a double thread or something :I
Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
26 Apr 2015 03:49 PM
As for issue #2 I'd convert the resultant Neck.C1 to EulerAnglesXYZ, and clamp the X and Z values, then it's just Neck.C1 = CFrame.Angles(newX, 0, newZ) + Neck.C1.p

This is what I used to test range of the EulerAnglesXYZ:

local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local Mouse = mouse
local character = player.Character or player.CharacterAdded:wait()
local Torso = character:WaitForChild("Torso")
local Weld = Torso:WaitForChild("Left Shoulder")
local Arm = character:WaitForChild("Left Arm")
local Neck = Torso:WaitForChild('Neck')
while wait() do --//game:GetService("RunService").RenderStepped:connect(function()
local ShoulderPos = (Torso.CFrame*(Weld.C0 + Vector3.new(-.5, 0, 0))).p
local negativeY = (mouse.Hit.p - ShoulderPos).unit
Weld.C1 = (CFrame.new(ShoulderPos +.5*negativeY,ShoulderPos + negativeY)*CFrame.Angles(math.pi/2,0,0)):toObjectSpace((Torso.CFrame*Weld.C0))
Neck.C1 = ((CFrame.new((Neck.Part0.CFrame * Neck.C0 * CFrame.new(0,0,.5)).p, Mouse.Hit.p + (Mouse.UnitRay.Direction * 1e10))) * CFrame.fromAxisAngle(Vector3.new(1,0,0), 0)):toObjectSpace(Neck.Part0.CFrame * Neck.C0)
print(("%.2f, %.2f, %.2f"):format(Neck.C1:toEulerAnglesXYZ()))
end--//)
Report Abuse
CrowClaws is not online. CrowClaws
Joined: 04 Jul 2010
Total Posts: 4466
26 Apr 2015 03:58 PM
@Cas Oh my god thanks!

Report Abuse
CrowClaws is not online. CrowClaws
Joined: 04 Jul 2010
Total Posts: 4466
26 Apr 2015 03:59 PM
@Cas slight problem...
What you made is for the left arm
The gun is in the right, I tried converting it but, I failed...

Could you?
Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
26 Apr 2015 04:10 PM
@Crow, All you have to do is change the indexes of the Weld and Arm, and change the sign of the half stud shift when calculating ShoulderPos. This also has some rudimentary clamping code.

local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local Mouse = mouse
local character = player.Character or player.CharacterAdded:wait()
local Torso = character:WaitForChild("Torso")
local Weld = Torso:WaitForChild("Right Shoulder")
local Arm = character:WaitForChild("Right Arm")
local Neck = Torso:WaitForChild('Neck')
while wait() do --//game:GetService("RunService").RenderStepped:connect(function()
local ShoulderPos = (Torso.CFrame*(Weld.C0 + Vector3.new(0.5, 0, 0))).p
local negativeY = (mouse.Hit.p - ShoulderPos).unit
Weld.C1 = (CFrame.new(ShoulderPos +.5*negativeY,ShoulderPos + negativeY)*CFrame.Angles(math.pi/2,0,0)):toObjectSpace((Torso.CFrame*Weld.C0))
Neck.C1 = ((CFrame.new((Neck.Part0.CFrame * Neck.C0 * CFrame.new(0,0,.5)).p, Mouse.Hit.p + (Mouse.UnitRay.Direction * 1e10))) * CFrame.fromAxisAngle(Vector3.new(1,0,0), 0)):toObjectSpace(Neck.Part0.CFrame * Neck.C0)
local X, Y, Z = Neck.C1:toEulerAnglesXYZ()
Z = math.abs(Z) < math.pi/2 and math.pi*Z/math.abs(Z) - Z or Z --// Clamps Z to math.pi + or - math.pi/2
Z = math.abs(Z) < math.pi - math.rad(70) and (math.pi - math.rad(70))*Z/math.abs(Z) or Z --// Reclamps lower end to + or - (math.pi - math.rad(70))
Neck.C1 = CFrame.Angles(X, Y, Z) + Neck.C1.p
print(("%.2f, %.2f, %.2f"):format(Neck.C1:toEulerAnglesXYZ()))
end--//)
Report Abuse
CrowClaws is not online. CrowClaws
Joined: 04 Jul 2010
Total Posts: 4466
26 Apr 2015 04:14 PM
The arm now awkwardly points up...

(Thanks so much! though!)
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