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: Arm pointing at mouse?

Previous Thread :: Next Thread 
EgoMoose is not online. EgoMoose
Joined: 04 Feb 2009
Total Posts: 2896
15 Dec 2015 08:59 PM
So I'm having difficulty doing this. Maybe I'm approaching it the wrong way?

There are two problems.

The first is that when going above the 90 degree mark things start getting wonky. I'm not entirely sure as to why, maybe someone could explain?

The second I understand the cause of the problem, but I'm not sure how to fix it. Because the vector in the fromAxisAngle constructor is changing when it should be relative to the object at all times. In short this means if my character faces one way may arms will do different directions than if I face the other.

Here's my code to save you time if you want to play around/test.

function rarm_func(player)
local this = {};

local rarmc = {
C0 = CFrame.new(1, 0.5, 0, 0, 0, 1, 0, 1, -0, -1, 0, 0);
C1 = CFrame.new(-0.5, 0.5, 0, 0, 0, 1, 0, 1, -0, -1, 0, 0);
};

local torso = player.Character.Torso;
local rshoulder = torso["Right Shoulder"];
local rarm = player.Character["Right Arm"];
local mouse = player:GetMouse();

local weld = Instance.new("Weld", torso);
weld.Part0 = torso;
weld.C0 = rarmc.C0;

local function onoff(bool)
weld.Part1 = bool and rarm or nil;
weld.C1 = rarmc.C1;
rshoulder.Part1 = bool and nil or rarm;
end;

local function update()
local vec = (mouse.Hit.p - (torso.CFrame * weld.C0).p).unit;
local angle = math.acos(vec:Dot(Vector3.new(0, -1, 0)))
weld.C1 = rarmc.C1 * CFrame.fromAxisAngle(vec, angle);
end

onoff(true);
game:GetService("RunService").RenderStepped:connect(update);
end;

wait(1); -- for character and stuff like that
rarm_func(game.Players.LocalPlayer);
Report Abuse
RegularTetragon is not online. RegularTetragon
Joined: 10 Oct 2009
Total Posts: 3085
15 Dec 2015 09:02 PM
I suggest you use the CFrame constructor
CFrame.new(Vector3 position, Vector3 point)
This creates a Vector3 located at the position you specify, pointing towards a point.
EXAMPLE:

CFrame.new(Vector3.new(0,0,0),Vector3.new(0,1,0))

Creates a CFrame that looks exactly up


It's delightful, It's delicious, It's delovely!
Report Abuse
EgoMoose is not online. EgoMoose
Joined: 04 Feb 2009
Total Posts: 2896
15 Dec 2015 09:10 PM
Hmm, I can see that as maybe being a solution to the first part, but wouldn't that give me the second problem still?
Report Abuse
RegularTetragon is not online. RegularTetragon
Joined: 10 Oct 2009
Total Posts: 3085
15 Dec 2015 09:15 PM
One possible source of error is that you're using acos, which returns a value (if I remember correctly) from 0 to pi/2, which is only one quadrant (0 to 90 degrees).

Anyway, you're probably overthinking it. That constructor should get around the whole angle thing, just make a new one every tick (Yeah, it's slow-ish, but if it's in a localscript then the server shouldn't care)


It's delightful, It's delicious, It's delovely!
Report Abuse
RegularTetragon is not online. RegularTetragon
Joined: 10 Oct 2009
Total Posts: 3085
15 Dec 2015 09:18 PM
CFrames, by the way, are a little finnicky when it comes to angles, because internally they are based on quaternions and externally they are based on rotation matrices. Neither of these are pretty to work with in terms of Euler angles (or with respect to themselves, quaternions are a little repulsive if you don't know the maths behind them). It's best to use methods that don't involve direct manipulation of rotation, ya catch my drift?


It's delightful, It's delicious, It's delovely!
Report Abuse
EgoMoose is not online. EgoMoose
Joined: 04 Feb 2009
Total Posts: 2896
15 Dec 2015 09:23 PM
Yeah, I believe I found a solution to the second problem in the form of setting the mouse caramel to object. That way the vector is always relative.

The problem I seem to be having now is with the constructor. I'm getting better results with fromAxisAngle, but I still haven't gotten it yet. I'm logging off for the night so maybe tmr.
Report Abuse
EgoMoose is not online. EgoMoose
Joined: 04 Feb 2009
Total Posts: 2896
15 Dec 2015 09:25 PM
For some reason I got auto corrected to caramel. I meant relative, as in object space.
Report Abuse
EgoMoose is not online. EgoMoose
Joined: 04 Feb 2009
Total Posts: 2896
16 Dec 2015 08:55 PM
Alright, bumping this post cause I still haven't got an answer.

I was able to get a relative vector, but the arm is still weird.

local offset = (torso.CFrame * weld.C0 * CFrame.fromAxisAngle(Vector3.new(0, 1, 0), -math.pi/2)):toObjectSpace(mouse.Hit).p.unit;
Report Abuse
nox7 is not online. nox7
Joined: 29 Aug 2008
Total Posts: 27467
16 Dec 2015 09:09 PM
"local offset = (torso.CFrame * weld.C0 * CFrame.fromAxisAngle(Vector3.new(0, 1, 0), -math.pi/2)):toObjectSpace(mouse.Hit).p.unit;"

What in blazes is that mess.

Joint.C1 = (CFrame.new((c.Torso.CFrame * Joint.C0 * OriginC1).p, Mpos) * CFrame.Angles(math.pi/2,0,0) * CFrame.new(0.5,-1,0)):toObjectSpace(c.Torso.CFrame * Joint.C0)

Is what you need. Where c is the character and OriginC1 is the saved C1 value BEFORE you start looping.
Report Abuse
EgoMoose is not online. EgoMoose
Joined: 04 Feb 2009
Total Posts: 2896
16 Dec 2015 09:21 PM
It's a unit vector. Because the fromAxisAngle would need the vector for its axis to be "indifferent" to which way the player is facing (eg. I want the same vector as long as my mouse is in front of my player in the same position, it shouldn't matter which way they're facing in the world).

Your method is def getting better results so thanks! I still need to tweak it though.
Report Abuse
EgoMoose is not online. EgoMoose
Joined: 04 Feb 2009
Total Posts: 2896
16 Dec 2015 09:38 PM
This is what I ended up using as a final product for anyone who may stumble upon this thread in the future.


local jointcf = torso.CFrame * weld.C0;
local new = (CFrame.new(jointcf.p, mouse.Hit.p) * CFrame.Angles(0, math.pi/2, math.pi/2) * rarmc.C1:inverse()):toObjectSpace(jointcf);

-- Process:
-- Get the angled CFrame with CFrame(pos, lookAt) constructor
-- Apply angles to spin the arm in preparation for the offset of C1 from offset point
-- Apply C1
-- Finally get the new CFrame relative to the offset point
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