How to make a projectile face a certain way?

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:

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?

2 Likes

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)
end

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.

New code
-- 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)
end
3 Likes

i would like to say that i understood at least 1% of what you said here but i really didn’t (i’m a beginner and i don’t know how any of that works)

this is how the knife’s position is being cast:

 local knifethrown = script.knifethrown:Clone()
		knifethrown.CFrame = Character:WaitForChild("Right Arm").CFrame + Vector3.new(0,-1,0)
 		knifethrown.Orientation = character:WaitForChild("HumanoidRootPart").CFrame.LookVector
 		knifethrown.Parent = workspace
 		debris:AddItem(knifethrown,15)

is there a simpler way to do it?

edit: this way of doing it is the one way that’s making the projectile face the wrong way

1 Like

Didn’t you ask how to make a part face a certain position. The functions I gave you do what you ask. Don’t worry about implementation details.

1 Like
		local knifethrown = script.knifethrown:Clone()
		knifethrown.CFrame = Stand:WaitForChild("Right Arm").CFrame + Vector3.new(0,-1,0)
		knifethrown.Orientation = character:WaitForChild("Torso").CFrame.LookVector
		knifethrown.Parent = workspace
		debris:AddItem(knifethrown,15)
		
		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)
    end

result:

image

still faces the wrong way after launching it

@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)

2 Likes