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

How to get the player's orientation?

Asked by 6 years ago

I noticed that when an object is a handle, its orientation remains constant even if the player spins around. Im trying to make a weapon that fires in the direction of the gun with 0 y and z orientation, but I can't find a way to get the x orientation value of the handle. This is what I have.

local EggX = game.Workspace.DeathLauncher.Handle.Orientation.X
missile.Orientation = Vector3.new(EggX, 0, 0)

(the gun shoots eggs) Maybe I could get the x orientation of the player, but I don't know how to do that. Any help on how to accomplish what I'm going for here?

1 answer

Log in to vote
0
Answered by
Vulkarin 581 Moderation Voter
6 years ago

Orientation gets pretty messy because it tends to breaks welds in scripts I would just change the CFrame instead, here's an example

missile.CFrame = CFrame.new(missile.Position, target.Position)

If you find that this leaves everything rotated the wrong way you can rotate them back by doing

missile.CFrame = (CFrame.new(missile.Position, target.Position)) * CFrame.Angles(0, math.pi/2, 0)

This will rotate the Y axis by 90 degrees, but you may rotate them as you want

0
Well, thank you dearly for the reply. I'm not familiar with CFrames and generally try to avoid them. I discovered that my system works some what when I use the Y value instead of the X, but it's shaky and occasionally it seems to go the wrong direction. As a last resort, I will try to use CFrames or just change the remade code more. Thank you for such a specific example very much though. tygerupercut3 68 — 6y
0
You're welcome but I would highly recommend learning CFrames, CFrames in general are nothing more than just a Position combined with an Orientation...Whenever you are moving parts CFrame is always the preferred method especially when you are dealing w/ parts that need to do something in a specific direction no matter where they are in the 3D world (you would use lookVector or rightVector of CFrame Vulkarin 581 — 6y
0
I understand. I know CFrames are used constantly in scripting and are very useful. Over time I will become familiar with CFrames and use them more often. tygerupercut3 68 — 6y
Ad

Answer this question