Position frame using rotation?

So, I want to create a 2d bullet/ray that moves forward based on rotation. Sort of like
CFrame * CFrame.new(0,0,-1) which is used to move 3d objects forward. How would you move a 2d object forward using GuiObject.Rotation? I couldn’t find anything about this and I suppose this uses math, but I am not good at it. If your wondering what im trying to make, it’s sort of “2D raycasting”. I want to try make a, if you will, raytracer that projects a 2D env to a first person 3d perspective. The reason I need to position using rotation is so the ray will shoot forward instead of always one direction.

You can convert the .Rotation into a 2d vector like so.

	local pointerDirection = Vector2.new(math.sin(math.rad(pointer.Rotation)),math.cos(math.rad(pointer.Rotation)))

I used it to point an GUI rectangle to another gui rectangle in this code example here.

If you are confused about the maths used it corresponds to the unit circle to convert the angle theta into XY coordinates which represent a direction vector (cos theta, sin theta), I believe I flipped the axis in the above example case as I wanted to be at 0 degrees the GUI rectangle is pointing up instead of horizontal like the unit circle example below.

image

Then use that as a unit vector to move it forward in whatever unit you want, scale or offset.

1 Like

Thanks! I will test this, I will tell you the results.

1 Like

May I ask, how would you use this to move forward?

EDIT: i think i got it, but i would like to be sure that its correct