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

Is there a way to create a directional value relative to the player?

Asked by 8 years ago

I haven no code snipits for this. Is there a way to find a direction relative to the player.

As in: If I would like to have something happen directly LEFT of the player, relative to their facing direction.

1 answer

Log in to vote
2
Answered by 8 years ago

eLunate taught me this :3

If you want to get a CFrame value say... directly left of the chatacter's torso, you would multiply the CFrame by a negative x value. Example,

local Left = Torso.CFrame * CFrame.new(-20,0,0)
It might be positive, I'm unsure.

He's the link to eLuante's answer.

Good Luck!

If I helped, please don't forget to accept my answer.
0
Thanks. I tried CFrame before but I was using + rather than multiplication. I'd like to ask though, why does multiplying it affect it in a relative manner? pmcdonough 85 — 8y
0
Well, first of all you can't add CFrames. And I'm not really sure. I asked eLuante and she didn't have an answer neither. Just something you have to remember I guess. Might be a good follow up question, but I'm not sure if anyone knows. I'm sure there's a reason though :3 User#11440 120 — 8y
0
The (extremely short and unhelpful) reason is that every CFrame corresponds to a spatial transformation. For instance, the CFrame(-20,0,0) corresponds to a translation 20 units in the direction -x, which relative to the player torso, is left. That is, the CFrame multiplication A * B gives the CFrame A transformed by B. My linear algebra is a little rusty, though, so I would look into it some more honeygold13843 136 — 8y
0
I assumed as much. Multiplying CFrames makes everything relative to each other was my mind process. User#11440 120 — 8y
Ad

Answer this question