Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Joint CFrame To mouse.hit Both are CFrame values?[Finally solved, figured it out myself :| ]

Asked by 9 years ago

What am I doing wrong. I want the object to face the mouse's hit position...

Here's the error " Players.Player1.Backpack.Plane.LocalScript:8: bad argument #3 to 'Angles' (number expected, got no value) " Line 8

local Player = Game.Players.LocalPlayer
local Mouse = Player:GetMouse()

while true do
local person = Player.Character
if person ~= nil then
local neck = workspace.Head.Neck
neck.NECK.C0 = neck.NECK.C0*CFrame.Angles (Mouse.Hit)
end
wait()
end

2 answers

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

Please note you have a typo on line 7 of your snippet. It probably should read:

local neck = person.Head.Neck
-- as opposed to using `workspace`

In addition, the Neck weld is actually stored in the Torso, rather than the Head.

and on line 8, you should just use neck.C0, not neck.NECK.C0. Snaps have no NECK property.


The position that a mouse is pointing at is Mouse.Hit.p.

We are going to inform the neck's weld based on this position.

However, we cannot simply directly use the mouse position. It's relative to the origin (a random space in the world) when we need it to be relative to the resting position of the head.

We know the target looking direction is looking from the position of the head and to the mouse. There's a CFrame constructor for this.

looking = CFrame.new( person.Head.Position , Mouse.Hit.p )

Again, though, this is relative to the origin, not the weld.

ROBLOX's default neck snaps are sort of strange, so we're going to just reset them to make them work nice.

Now we can just use the toObjectSpace method of CFrames to get what we need for C1:

neck.C1 = CFrame.new();
neck.C0 = CFrame.new(0, 1.5, 0);
-- Reset, because we need the head to be in the
-- right place for the ObjectSpace calc
neck.C0 = CFrame.new(0, 1.5, 0) * person.Head.CFrame:toObjectSpace(
    looking
)

And that's that!


This will look up and down, too, though. If you don't want that, or maybe you just want to reduce the amount, you can modify looking.

from = person.Head.Position
to = Mouse.Hit.p

displacement = to - from
displacement = displacement * Vector3.new(1, 0.1 , 1)
-- Only 10% up and down as before
to = from + displacement
looking = CFrame.new(from, to)
0
Sorry, but there's it's labeled as neck and NECK. Its a custom mech with Motor6D's. Neck is the part while NECK is the Motor6d. This is not a Humanoid object. It's a vehicle. Orlando777 315 — 9y
0
Sorry, but there's a reason why it's* Orlando777 315 — 9y
0
BTW, what is "looking" mouse.hit.p? Orlando777 315 — 9y
0
Nvm on the looking, didnt see the variable. Orlando777 315 — 9y
0
Doesnt work. It spazzes the head. And it's not facing in the direction pointed. Orlando777 315 — 9y
Ad
Log in to vote
-1
Answered by 9 years ago

I pretty sure Mouse.Hit by itself is an object and not a value so try

neck.NECK.C0 = neck.NECK.C0*CFrame.Angles(Mouse.Hit.p)
0
Same Error :c Orlando777 315 — 9y
0
BTW According to "http://wiki.roblox.com/index.php?title=API:Class/Mouse/Hit" Hit is the CFrame value. A position, there's no P value to hit. Orlando777 315 — 9y
0
Maybe I meant Mouse.Target.p xImmortalChaos 565 — 9y
0
Target is an object. Orlando777 315 — 9y
0
Ik but .p is it's position which is a vector3 xImmortalChaos 565 — 9y

Answer this question