Answered by
8 years ago Edited 8 years ago
Simply multiply the head CFrame by another CFrame
It's weird how this is calculated, but it fits best with your problem. Lookvector
is a property of all CFrames
, and it tells which direction the CFrame
is facing.Lookvector
can be vary useful, but when you want to get a position from a CFrame
, you can multiply it by another CFrame
.
In our case, we want the CFrame to go behind the had and slightly above it. A positive Z is behind, and a Negitive Y is above.
To make a CFrame a Vector3
, we just use the .p
after the CFrame which turns it into a position.
1 | local player = game.Players.LocalPlayer |
2 | local character = player.Character |
3 | local dexbot = script.Parent |
4 | local pos = dexbot.BodyPosition |
7 | pos.Position = (char.Head.CFrame * CFrame.new( 0 , 3 , 2 )).p |
Doesn't work? Keep reading.
Still isn't working?
This is because you're either A.) Using a Local Script in workspace, or B.) Using Local Player in a regular script.
To fix this, get the player with the PlayerAdded event, and get the character with the CharacterAdded event. Also make sure to use a RegularScript.
01 | game.Players.PlayerAdded:connect( function (plr) |
02 | plr.CharacterAdded:connect( function (char) |
03 | local dexbot = script.Parent |
04 | local pos = dexbot.BodyPosition |
07 | local c = char.Head.CFrame * CFrame.new( 0 , 3 , 2 ) |
If tested this and it works fine.
Cloning this to new players
Just use the Clone() function and set it to new players if you want them to all have the orb.
01 | game.Players.PlayerAdded:connect( function (plr) |
02 | plr.CharacterAdded:connect( function (char) |
03 | local dexbot = script.Parent:Clone() |
04 | dexbot.Parent = workspace |
05 | local pos = dexbot.BodyPosition |
07 | pos.Position = (char.Head.CFrame * CFrame.new( 0 , 3 , 2 )).p |
I tested this and it works fine.
I got all of the following information in the following places,
- eLunate's answer on how to get the position according to a CFrame
- Wiki Body Position
- Wiki CFrames
- Wiki PlayerAdded Examples
- Wiki CharacterAdded Examples
- Wiki Clone Function
Good Luck!
if I helped, please don't forget to accept my answer.