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

Problem with lookVector/body thrust?

game:GetService("UserInputService").InputBegan:connect(function(key)
	if key.KeyCode == Enum.KeyCode.Space then
		local pos = Instance.new("BodyThrust",player.Character.Torso)
			
		local look = char.Torso.CFrame.lookVector
			
		pos.Force = Vector3.new(0,6000,0)+Vector3.new((look.X*4000),0,(look.Z*4000))
		game.Debris:AddItem(pos,.2)
	end
end)

Whenever I run this, it makes the character move in weird directions. Is there an issue with the way I use lookvector, is it something with body thrust.

1 answer

✓ Accepted answer

Line 7 confuses the direction you're trying to launch your character. Also it isn't necessary to use a BodyThrust here so if I where you I would just change the velocity (Like I did in my code). Also keep in mind if you're trying to have this cross platform (Mobile, XBox Ect.) you're going to have to add more KeyCodes or you can change this script so it triggers when the character jumps

game:GetService("UserInputService").InputBegan:connect(function(key)
    if key.KeyCode == Enum.KeyCode.Space then
     	game.Players.LocalPlayer.Character.HumanoidRootPart.Velocity = Vector3.new(0,100,0)+game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame.lookVector*50
    end
end)

ps. Awesome username dude!

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