Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Question on lookVector?

I'm trying to teleport in front of the block, not on top of it. I figured lookVector would be the way to go because it it the direction the block is facing. However I'm not very experienced in using it. Am I doing this wrong? Everything is defined, exists, etc.

for _,v in pairs(workspace.Bricks:GetChildren()) do
	if v.Name == "GreenBrick" then
		if v.CanTeleport.Value == true and v ~= script.Parent then
			print(v.CFrame.lookVector)
			char:MoveTo(v.Position * v.CFrame.lookVector)
		end
	end
end

2 answers

The :MoveTo method automatically detects collisions in moving, and tries to put the moved model in the topmost unoccupied space. You must be trying to move your model somewhere inside something, which cause MoveTo to put your model on top of the part instead.

1 comment

0

Exactly. Thats why I am trying to change the position that it is trying to move the character to so that it places it in front of the brick.

v.Position * v.CFrame.lookVector doesn't really mean anything unless you're specifying the origin is for some reason very important.


You probably want to add them -- v.Position + 5 * v.CFrame.lookVector* would be 5 studs away from v.Positionin the direction ofv.CFrame.lookVector`.

As per iconmaster's suggestion, you shouldn't use :MoveTo if you want it to be exactly at this position. Instead, you should set the CFrame of the thing you're moving (presumably char is a Character and you'd set the .CFrame of the Torso)

This discussion is preserved as it was. New answers, comments, and votes are closed.