You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve?
I’m making a game where you can launch yourself with a shotgun in a direction and you will travel in an arc. Currently I’m just changing the humanoidstatetype to physics and then using a body velocity to launch the character and then quickly deleting the body velocity. -
What is the issue?
If I launch myself into a corner, my character will just fling. I have no code that is causing it to happen so I’m assuming this is just a bug with the physics state type.
As you can see in the video, the character flies in an arc as intended but as soon as I launch myself into a corner, sometimes the character will just start accelerating to the left.
Here is my firing method to show that the only velocity I’m adding to the character is the bodyvelocity which instantly gets deleted.
function module:Fire()
if not self:CanFire() then return end
self.Bullets -= 1
local t = tick()
self.LastShot = t
local self:module = self
local hum:Humanoid = self.Humanoid
hum.WalkSpeed = 0
local dir = (self.HRP.Position - self.MousePos).Unit
local bv = Instance.new("BodyVelocity", self.HRP)
bv.MaxForce = Vector3.new(1000000,1000000)
bv.Velocity = dir * 70
ds:AddItem(bv, 0.1)
task.wait()
hum:ChangeState(Enum.HumanoidStateType.Physics)
local running = true
local params = RaycastParams.new()
params.FilterDescendantsInstances = {self.Character}
params.FilterType = Enum.RaycastFilterType.Exclude
task.delay(0.05,function()
hum.WalkSpeed = 16
end)
if dir.Y > 0.2 then
task.wait(0.1)
end
local c
task.delay(1,function()
if running and self.LastShot == t then
hum:ChangeState(Enum.HumanoidStateType.GettingUp)
end
end)
local lastVelocity = self.HRP.AssemblyLinearVelocity
c = run.RenderStepped:Connect(function()
if self.LastShot ~= t then
c:Disconnect()
return
end
local rdir = self.HRP.AssemblyLinearVelocity.Unit
local ray = workspace:Raycast(self.HRP.Position - rdir * 2, rdir * 6, params)
local ray2 = workspace:Raycast(self.HRP.Position+Vector3.yAxis, Vector3.yAxis * -5, params)
local ray3 = workspace:Raycast(self.HRP.Position, Vector3.yAxis * -4, params)
if ray2 or ray3 then
self:Reload()
running = false
c:Disconnect()
hum:ChangeState(Enum.HumanoidStateType.GettingUp)
end
if ray then
hum:ChangeState(Enum.HumanoidStateType.GettingUp)
end
end)
local c2
c2 = hum.StateChanged:Connect(function(old, new)
if new == Enum.HumanoidStateType.Landed then
c2:Disconnect()
self:Reload()
end
end)
end
-
What solutions have you tried so far?
I’ve tried manually checking for if the character gets flung by doing this but it doesn’t work perfectly and sometimes triggers when I’m just launching normally.
local hum:Humanoid = script.Parent:WaitForChild("Humanoid")
local hrp:BasePart = script.Parent:WaitForChild("HumanoidRootPart")
local lastVelocity = hrp.AssemblyLinearVelocity
local lastState = hum:GetState()
while task.wait() do
local currentVelocity = hrp.AssemblyLinearVelocity
local currentState = hum:GetState()
if currentState == Enum.HumanoidStateType.Physics and lastState == Enum.HumanoidStateType.Physics then
if currentVelocity.Y - lastVelocity.Y > 5 then
hum:ChangeState(Enum.HumanoidStateType.GettingUp)
elseif math.abs(currentVelocity.X - lastVelocity.X) > 3 then
hum:ChangeState(Enum.HumanoidStateType.GettingUp)
end
end
lastState = currentState
lastVelocity = currentVelocity
end
Again, I am absolutely convinced that this is just a physics bug but I’m not sure atp.