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

how to make orb follow to the side of player?

Asked by 9 years ago

I'm trying to get an orb to always stay on the right side of the player.

i know have to do something with angles but i keep getting errors.

what i've got just makes the orb follow behind the players head

whenever i try to use angles i get incompatible error.

i guess angles is incompatible with position?

this script is inside the orb

and i'm using a BodyPosition to move it around

the orb is inside the players head

local Part = script.Parent local BodyPosition = script.Parent.BodyPosition local Character = script.Parent.Parent

while Part and Part.Parent and wait(.1) do BodyPosition.position = Character.Head.Position + -Character.Head.CFrame.lookVector*2 end

2 answers

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

You actually have to rotate the Head's CFrame before taking it's lookVector, since Vector3s don't support any kind of "rotation":

local Part = script.Parent
local BodyPosition = script.Parent.BodyPosition
local Character = script.Parent.Parent

while Part and Character and wait(.1) do
    BodyPosition.position = Character.Head.Position + 
        (Character.Head.CFrame*CFrame.Angles(0, math.rad(90), 0)).lookVector*2
    --If 90 doesn't work, try -90.
end
0
worked perfect ty so much! yes -90 for right side. I was so close a few times but just couldnt get the formula right. much appreciated johnnygadget 50 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

If I were you, I'd just add a vectorToWorldSpace value to the bodyposition.

--Assuming the script is within the orb within the head
while wait(0.1) do
BodyPosition.position = script.Parent.Parent.Position + script.Parent.CFrame:vector.ToWorldSpace(Vector3.new(0,10,0))
end

The Vector3 value inside of the vectorToWorldSpace is the offset at which the orb follows your head

Answer this question