You can write your topic however you want, but you need to answer these questions:
-
**What do you want to achieve? I have a system that uses apply impulse to fire the players character, the problem is that it is inaccurate and the farther I need to shoot the player the worse the accuracy gets.
-
What is the issue? Include screenshots / videos if possible!
This is the way I am firing the player, I want them to end up exactly at the end point.
cannon.FireCannon = function(plr, startPos, EndPos)
local direction = (EndPos - startPos)
local horizontalDistance = (Vector3.new(direction.X, 0, direction.Z)).Magnitude
local heightDifference = (Vector3.new(0, direction.Y, 0)).Magnitude
local gravity = game.Workspace.Gravity
local duration = math.log(1.001 + horizontalDistance * 0.01)
local normalizedDirection = direction.Unit
local horizontalForce = horizontalDistance / duration
local verticalForce = (gravity * duration * 0.5) + (heightDifference / duration) * 2
local force = Vector3.new(
horizontalForce * normalizedDirection.X,
verticalForce,
horizontalForce * normalizedDirection.Z
)
local char = plr.Character
local ogSpeed = char.Humanoid.WalkSpeed
local mass = 0
char.Humanoid.WalkSpeed = 0
task.wait(.6)
task.spawn(camFollow, char, EndPos, duration) --ignore this
task.wait(.11)
print(char.HumanoidRootPart.Mass)
for i, v in pairs(char:GetDescendants()) do
if v:IsA("BasePart") then
mass += v.Mass
end
end
print(mass)
-- print(char.AssemblyMass)
char.HumanoidRootPart:ApplyImpulse((force * mass * 1.009))
task.wait(duration)
char.Humanoid.WalkSpeed = ogSpeed
char.HumanoidRootPart.Position = EndPos
end
- What solutions have you tried so far? I have looked through the forums but cant quite find anything useful.