I made a projectile throw script that works just fine but when it grabs the model from i.e Replicated storage, it keeps that position and it doesn’t face the way of the actual trajectory, for example take this image:
say the gray part is the trajectory and the knife is the projectile, It follows the trajectory normally but facing that way, How do i make it not do this?
Since roblox deprecated the constructor that did this, they provided an alternative.
function lookAt(target, eye)
local forwardVector = (eye - target).Unit
local upVector = Vector3.new(0, 1, 0)
-- You have to remember the right hand rule or google search to get this right
local rightVector = forwardVector:Cross(upVector)
local upVector2 = rightVector:Cross(forwardVector)
return CFrame.fromMatrix(eye, rightVector, upVector2)
You would pass the vector where you want it to look at first, and then the position where you want it to be. lookAt(look, position)
But that was super confusing for me since the old constructor was CFrame.new(position, look) so I tweaked it up a bit to keep consistency with the now deprecated constructor.
-- I personalized it a bit. You can too. It just reverses the order of arguments.
local function look_at(position, look)
local look_vector = (look - position).Unit
local right_vector = look_vector:Cross(Vector3.new(0, 1, 0))
local up_vector = right_vector:Cross(look_vector)
return CFrame.fromMatrix(position, right_vector, up_vector)
@Jerememez You just simply need to set the Cframe of the projectile to be Cframe.new(projectile.Position,whatEverNeedsToBeFaced.Position)
So for example, if you wanted it to look at your mouse hit position it would just be
projectile.CFrame = CFrame.new(projectile.CFrame,mouse.Hit.p)