Hello. I am trying to make a thing where if i press shift and x it launches me forward. I have a script but instead of launching me forward it launches me back. Heres an example of a game that I play that has it:
as you can see the player launches forward and a little bit up. I want it to be the same. here is my code:
local Player = game.Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
Player.CharacterAdded:Connect(function(char)
character = char
humanoid = character:WaitForChild("Humanoid")
end)
local function getModelMass(model: Model): number
local mass = 0
for _, v in ipairs(model:GetDescendants()) do
if v:IsA('BasePart') then
mass += v:GetMass()
end
end
return mass
end
-- force = mass * acceleration
local fowardForce = getModelMass(character) * 85
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if (input.KeyCode == Enum.KeyCode.LeftShift and UIS:IsKeyDown(Enum.KeyCode.X)) or (input.KeyCode == Enum.KeyCode.X and UIS:IsKeyDown(Enum.KeyCode.LeftShift)) then
print("Wow")
humanoid.PlatformStand = true
character.HumanoidRootPart:ApplyImpulse(-character.HumanoidRootPart.CFrame.LookVector.Unit * fowardForce)
wait(5)
humanoid.PlatformStand = false
end
end)
this is an example of what I’m trying to achieve. Not just going forward but a little bit up:
You have a slight issue in your code on the line where the impulse is applied. You’re automatically making it minus, also I don’t think you need to turn it into a Unit vector since LookVector is already a unit. Here’s your code:
-- < HERE > --
character.HumanoidRootPart:ApplyImpulse(-character.HumanoidRootPart.CFrame.LookVector.Unit
fowardForce)
Oh! My bad. I didn’t see my error. Also! It worked. But I noticed it makes the player launch just forward. is it possible to make it launcher the player forward but also slight up?
character.HumanoidRootPart:ApplyImpulse(character.HumanoidRootPart.CFrame.LookVector *
fowardForce + character.HumanoidRootPart.UpVector * 10) -- You can change this however you wish.
local Player = game.Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
Player.CharacterAdded:Connect(function(char)
character = char
humanoid = character:WaitForChild("Humanoid")
end)
local function getModelMass(model: Model): number
local mass = 0
for _, v in ipairs(model:GetDescendants()) do
if v:IsA('BasePart') then
mass += v:GetMass()
end
end
return mass
end
-- force = mass * acceleration
local fowardForce = getModelMass(character) * 85
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if (input.KeyCode == Enum.KeyCode.LeftShift and UIS:IsKeyDown(Enum.KeyCode.X)) or (input.KeyCode == Enum.KeyCode.X and UIS:IsKeyDown(Enum.KeyCode.LeftShift)) then
print("Wow")
humanoid.PlatformStand = true
character.HumanoidRootPart:ApplyImpulse(character.HumanoidRootPart.CFrame.LookVector *
fowardForce + Vector3.new(0,10,0))
wait(5)
humanoid.PlatformStand = false
end
end)
It actually does launch you up, it’s just that the force is so small that it’s not noticable. You also need to take your character’s mass into account like you did with the forward force
local mass = getModelMass(character)
local fowardForce = mass * 85
local upForce = mass * 40
character.HumanoidRootPart:ApplyImpulse(character.HumanoidRootPart.CFrame.LookVector *
fowardForce + Vector3.new(0,upForce,0))