Making a Look vector turn left or right

Hello, recently i was making a hook that makes the character go towards the mouse with a body velocity, but it’s pretty hard to use it because i can’t go right or left, is there a way to do this?

I don’t need a entire script just a math function or something like that.

I searched in internet and devforum and i found a way but it keeps turning left (or right) and doesn’t go towards the mouse, i need the character to turn left just a bit and keep going toward the mouse

2 Likes

You can’t make a CFrame.LookVector to left or right, it can only go to the front direction. Instead, you may want to rotate the character to look at the mouse, then you only use LookVector to go towards the mouse.

3 Likes

But the hook already go towards the mouse i need it to make curves

1 Like

Why not use CFrame.RightVector and -CFrame.RightVector?

1 Like

Because the mouse can be in different positions and i can’t preview all of them manually

Try this.

(Part.CFrame * CFrame.Angles(math.pi/2, 0, 0)).LookVector

Important things to know:

  • math.pi/2 represents 90 degrees
  • If the lookvector turned in the wrong direction, move the ‘math.pi/2’ to another position in the CFrame.Angles value
  • If the lookvector turned the opposite direction to your likings, put a subtraction sign (-) in front of the ‘math.pi/2’ like so:
(Part.CFrame * CFrame.Angles(-math.pi/2, 0, 0)).LookVector
3 Likes

Hello, (sorry for the late answer) it worked pretty well but the player go left while going backwards, i want it to go left (or right) while going forwards, how can i do this? I tried placing the math.pi/2 in the other 2 values but didn’t worked

Thats my code by the way

Connection = RunService.Stepped:Connect( function()
		
		if Direction == "straight" then
			
			BodyVelocity.Velocity = CFrame.new(RootPart.Position, MouseHitp).LookVector * VelocityMultiplier
			
		elseif Direction == "left" then
			
			BodyVelocity.Velocity = (CFrame.new(RootPart.Position, MouseHitp) * CFrame.Angles(0, math.pi/2, 0)).LookVector * VelocityMultiplier
		end
		
		BodyGyro.CFrame = CFrame.lookAt(RootPart.Position, MouseHitp)
	end)

Nevermind i find out how, because you said math.pi/2 represents 90 degrees so i increased the 2 to 4 and now it’s like 45 degrees

1 Like
function Turn(
	mycframe, -- current cframe
	V3		  -- orientation offset
	-- Example: if u want to turn left, the V3 should be (0,90,0)
)
	
	return mycframe:ToWorldSpace(
		CFrame.Angles(
			math.rad(V3.X)
			,
			math.rad(V3.Y)
			,
			math.rad(V3.Z)
		)
	)
end

MyPart = workspace.Part

MyPart.CFrame = Turn(MyPart.CFrame,Vector3.new(0,30,0)) --Turning the part 30 degrees to the left
2 Likes

É mesmo em vez de math.pi/4 eu podia só escrever 45 valeu pela dica

sim mas daí tem que usar math.rad()

o que math.rad() faz? Na api fala que ele retorna o angulo dado em graus em radianos, mas oq sao radianos?

radianos é um tipo de medida estranha q n sei para que serve,
mas enquanto uma volta inteira é 360 em graus, em radianos é 2 * π
180 = π
45 = π / 4
image
tem isso no roblox pq eles usam radianos ao invés de graus na função CFrame.Angles()

2 Likes

kkk eu tava tentando descobrir isso desde 2019 mas nunca pesquisei muito fundo valeu ae