hello, im making a football game, in my game when you shoot the ball the weld between you and balls weld.part1 becomes nil and a bodyvelocity gets applied to the ball for a short amount of time but the problem is when you do this, ball gets so far away, if i lower the velocity of bodyvel then it becomes slow what should i use?
recording:
https://gyazo.com/4674e03d3fe661c810571b716f6b9627
here is the code:
|
|
chr.Humanoid:LoadAnimation(game.ReplicatedStorage.Shoot1):Play() |
|
|
local ball = workspace.Ball.Part |
|
|
ball:SetNetworkOwner(nil) |
|
|
ball.BallWeld.Part0 = nil |
|
|
ball.CanCollide = true |
|
|
local shoot = Instance.new(BodyVelocity,ball) |
|
|
shoot.MaxForce = Vector3.new(1000,1000,1000) |
|
|
shoot.P = math.huge |
|
|
shoot.Velocity = chr.HumanoidRootPart.CFrame.LookVector * (60) |
|
|
game.Debris:AddItem(shoot,.1) |
- use ``` to format code blocks
- It looks like you aren’t creating
BodyForce correctly.
- You can simply set the
AssemblyLinearVelocity instead of using a BodyForce
chr.Humanoid:LoadAnimation(game.ReplicatedStorage.Shoot1):Play()
local ball = workspace.Ball.Part
ball:SetNetworkOwner(nil)
ball.BallWeld.Part0 = nil
ball.CanCollide = true
local horizontalVelocity = 200 -- Adjust to your liking
local veritcalVelocity = workspace.Gravity + 100 -- Also adjust to your liking
local vel = chr.HumanoidRootPart.CFrame.LookVector * horizontalVelocity + Vector3.new(0,verticalVelocity,0)
ball.AssemblyLinearVelocity += vel
2 Likes
its very good it works better now but the problem is after the ball lands, it goes infinitely
1 Like
Is it really going infinitely or is it just rolling super far? Because if it’s going infinitely then I have no idea how to fix it because its simply not possible for that to happen, but it it’s rolling you can probably just increase the part’s friction with CustomPhysicalProperties
1 Like
its rolling super duper far, i tried increasing its friction i made it max (which is 2) but i dont think it really fixed it,
1 Like
You can probably detect when it hits the ground and dampen/reset its velocity.
1 Like
i thought about that too but since this is going to be a soccer game there will be ground shoots which wont make ball go to air
1 Like
Is this still the code being used or has it changed?
1 Like
it has changed, the current one is this:
playsfx(game.ReplicatedStorage.shoots,chr.HumanoidRootPart)
game.ReplicatedStorage.Events.CameraShake:FireClient(plr,"Shoot")
chr.Humanoid:LoadAnimation(game.ReplicatedStorage.Shoot1):Play()
local ball = workspace.Ball.Part
ball:SetNetworkOwner(nil)
ball.BallWeld.Part0 = nil
ball.CanCollide = true
local horizontalVelocity = 150
local verticalVelocity = 50
local vel = chr.HumanoidRootPart.CFrame.LookVector * horizontalVelocity + Vector3.new(0,verticalVelocity,0)
ball.AssemblyLinearVelocity += vel
ball:SetAttribute("BallOwner",nil)
Does the velocity ever delete?
what do you mean? its not using the bodyvelocity anymore. and the code provided is the one im using nothing less or more.
Yeah I mean the AssemblyLinearVelocity, does it ever go to 0 or delete at all?
i just checked it and it stays like that forever
18:07:17.010
-9.809558868408203, 50, -149.67889404296875 (x4996) - Server - Main:55
That might be the problem, if it stays forver then the velocity will keep pushing it
Try deleteing it after 0.1 seconds using Debris
delete the assemblylinearvelocity?
In my experience AssemblyLinearVelocity doesn’t stay the same, which is confusing as for why it does for you.
Yes or set it to 0, 0, 0 if you plan to reuse it
You can’t, it’s a property. You can set it to Vector3.zero after one frame though.
Yea set it to 0 so that it wont keep pushing it forever
i did it and its a bit weird
clip:https://gyazo.com/89686d6af9585156bd0a9d0069bcff37
code:
local horizontalVelocity = 150
local verticalVelocity = 50
local vel = chr.HumanoidRootPart.CFrame.LookVector * horizontalVelocity + Vector3.new(0,verticalVelocity,0)
ball.AssemblyLinearVelocity += vel
task.delay(.1,function()
ball.AssemblyLinearVelocity = Vector3.zero
end)
ball:SetAttribute("BallOwner",nil)