Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i use body velocity in the direction that im facing?

Asked by 4 years ago
Edited 4 years ago

im trying to get an animation that is moving the HRP with a bodymover so far i was using bodyposition to move the hrp to the end of the animation but its a little glitchy so im think of using body velocity to move the hrp while the animation (changed the animation to not move) is moving but i have no way to tell what direction the player is facing so i cant move the body velocity based on what direction the character is facing, i know that i might be able to use orientation but idk how. can someone show me a strip of code to help me heres my code.

mouse = game.Players.LocalPlayer:GetMouse()
player = game.Players.LocalPlayer
humanoidrootpart = player.Character.HumanoidRootPart
bodymover = game.Workspace.BodyVelocity
mouse.KeyDown:Connect(function(key)
bodymover.Parent = humanoidrootpart

if string.lower(key) == "q" then



end
end)

the idea here is that when q is pressed the still animation will play and the bodyvelocity will move it in the direction that the person is facing then when the animation stops bodyvelocitiy will be set to 0. this is a very early script so i barely have anything on it.

2 answers

Log in to vote
0
Answered by
Osamiku 12
4 years ago
Edited 4 years ago

If you are making a script where you want your character to boost forward I've made one you might like:

local plr = game.Players.LocalPlayer
local Char= plr.Character or plr.CharacterAdded:Wait()
local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character

local Tapped = true
local Time = 0.25
local Cooldown = false

UserInputService.InputBegan:Connect(function(Input, GameStuff)
 if GameStuff then return end
 if Input.KeyCode == Enum.KeyCode.q and Cooldown == false then -- edit the "Enum.KeyCode.1" to whatever key you want for it to happen.
  if not Tapped then
   Tapped = true
   wait(Time)
   Tapped = false
  else
   Char.HumanoidRootPart.Velocity = Char.HumanoidRootPart.CFrame.lookVector*150 -- this number is how far you go when you press the desired key to boost
   Cooldown = true
   wait(2) -- this is the seconds of how long you have to wait before boosting again
   Cooldown = false
  end
 end
end)

it has a cool down too. notes are in the script if you want to change anything

also put it in the startercharacterscripts as a local script.

0
thank you for the answer, i dont fully understand the script but i will take time to examine the script xxbrobroxx02 13 — 4y
Ad
Log in to vote
0
Answered by
AspectW 431 Moderation Voter
4 years ago

HumanoidRootPart.CFrame.LookVector.Unit * How many studs forward

Answer this question