I have made a gun like script to fire a projectile and I came across this logic error. The part is facing the direction it is traveling just at the wrong orientation, the wrong side is facing the direction of travel. This picture shows the syringe's point facing the ground with the side of the syringe facing the point. I want the point of the projectile facing the direction of travel. This is the positioning code I used.
local spawnPosition = (Right.Doctor.Syringe.CFrame * CFrame.new(2, 0, 0)).p bullet.CFrame = CFrame.new(spawnPosition, mouse.hit.p) -- This is the positioning line I have set it to bullet.Velocity = bullet.CFrame.lookVector * 60 -- 60 is speed bullet.Parent = game.Workspace
On line 2 I have set it to face the position the mouse was at when the mouse clicked. I have tried changing the orientation with radians, but that hasn't works so far, yet I am fairly new with radians, so I may be using them inaccurately. This was my raidan attempt:
bullet.CFrame = CFrame.new(spawnPosition, mouse.hit.p*(1/2*math.pi))
However there was no change in rotation of the syringe(bullet)
You want to rotate the part correctly by multiplying its CFrame by some rotation:
local spawnPosition=(Right.Doctor.Syringe.CFrame*CFrame.new(2,0,0)).p local cframe=CFrame.new(spawnPosition, mouse.hit.p) bullet.CFrame=cframe*CFrame.Angles(math.pi/2,0,0) bullet.Velocity=cframe.lookVector*60 bullet.Parent=workspace
bullet.CFrame = CFrame.new(spawnPosition, mouse.hit.p) * CFrame.Angles() bullet.Velocity = (bullet.CFrame * CFrame.Angles()).lookVector * 60
You can try messing up with the angles this way