How do I add an angle to LookVector?

How can I add an angle to the current LookVector to make it more downwards? I have a slash attack that goes forward(direction, LookVector) from the HumanoidRootPart, but when I jump, I want it to go downwards. But, I don’t know how to add on to a LookVector, so I need help.

I have tried multiplying the LookVector with CFrame.Angles() but it is not working and it says I need a Vector3. I tried to do Orientation but I just don’t know anymore. If there is any solutions to this or alternative solutions I just need to know.

if player.Character.Humanoid:GetState() == Enum.HumanoidStateType.Freefall then
			local downdirection = CFrame.Angles(0,math.rad(90),0)
			end
		
			local rainbowslash = game.ServerStorage.rainbowslash:Clone()
			print("rainbowslash clone")
			rainbowslash.Parent = player.Character.Head
			rainbowslash.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(math.random(-1,1),math.random(-1,1),-1)
			rainbowslash.Orientation = rainbowslash.Orientation + Vector3.new(180,0,math.random(-100,100))

		local vel = Instance.new("BodyVelocity", rainbowslash) --velocity
			vel.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
			print(player.Character.HumanoidRootPart.CFrame.LookVector)
			vel.Velocity = player.Character.HumanoidRootPart.CFrame.LookVector * speed -- I don't know how to add an angle to this, I want to make it more downwards (I want to add on downdirection variable to this but it just wont work, it has errors)
			print(vel.Velocity)
		game.Debris:AddItem(rainbowslash,lifetime)
6 Likes

Try this

vel.Velocity = (player.Character.PrimaryPart.CFrame * CFrame.Angles(math.rad(-ANGLE), 0, 0)).LookVector * Speed
8 Likes

I’m about to try it but can you explain to me how it works or what it does?

It turns the LookVector into a CFrame which allows you to multiply by CFrame.Angles to effectively rotate the angle of the velocity in object space. The ANGLE value is how much you rotate by in degrees in object space relative to the LookVector of the HumanoidRootPart.

2 Likes

If you just want to turn LookVector 90 degrees, just use UpVector or -UpVector.

vel.Velocity = player.Character.HumanoidRootPart.CFrame.UpVector * -speed -- the - makes the upvector go the opposite direction

If you wanted to rotate by any angle, you could rotate the CFrame first before getting its LookVector.

vel.Velocity = (player.Character.HumanoidRootPart.CFrame * CFrame.Angles(math.rad(45), 0, 0)).LookVector * speed

(I put the 45 on the first slot in CFrame.Angles because that’d pitch the CFrame forward to make it face down if it were facing forward before, instead of yawing it, making it turn right/left as that CFrame.Angles in your code would.)

(Edit: That is, CFrame.Angles’s axes are X, Y and Z, whereas Orientation’s angles are Y, X, Z. So CFrame.Angles(math.rad(90), 0, 0) is (almost) the same as CFrame.fromOrientation(0, math.rad(90), 0)

2 Likes

Fixed

Try this vel.Velocity = (player.Character.PrimaryPart.CFrame * ( CFrame.Angles(math.rad(-ANGLE), 0, 0)).LookVector * Speed )

vel.Velocity = (player.Character.HumanoidRootPart.CFrame * CFrame.Angles(math.rad(45), 0, 0)).LookVector * speed

can you explain why 45 is in the brackets?

its my really first time using CFrames with LookVector

It’s in parentheses because it is calling the math.rad function. It’s the same as why this is in parentheses.
print("test")
CFrames use radians, and math.rad turns degrees into radians.

1 Like

just realized that it isnt Angles(math.rad(x, y, z)) but Angles(math.rad(x), y, z)

i am making hitbox for dagger ability and hitbox part which is a cylinder is set vertically, i want it to be horizontally

hitbox.CFrame = character.HumanoidRootPart.CFrame + character.HumanoidRootPart.CFrame.LookVector

heres how it looks, i have to rotate it by 90 degrees on z axis

i figured by myself it out, thanks anyways

solution:

hitbox.CFrame = character.HumanoidRootPart.CFrame * CFrame.Angles(0, 0, math.rad(90))
1 Like