How would I go about kicking a ball?

I mean, if, for instance the part of the player was his foot - and its velocity was, for example, (0, 15, 24), you just take this velocity and apply it to the part, but since a human leg irl has more mass you just multiply the velocity by, idk, may be 5?

1 Like

I’m sorry but, I’m still confused. I only know the basics of scripting and nothing else. I am still currently in the learning faze of Lua.

1 Like

Roblox is its own physics engine and im sure you wouldnt want them scoring exactly where they clicked, that’d be unfair so we dont need fancy orbital physics or projectile motions you can just use the roblox physics engine and apply a body force to the soccer ball according the the lookvector of the player when they touched it

1 Like

The way Roblox soccer games usually go on to do this (TPS: Ultimate Soccer, RES) is by parenting a BodyVelocity to the ball, with the velocity property of the BodyVelocity being set to the leg CFrame look vector.
They usually parent the body velocity inside the ball for 0.3 seconds, when .Touched event fires and a few checks passes inside the .Touched event.

However, you can use the recently released BasePart:ApplyImpulse() methods that I believe achieve a far better result instead, rather than using a legacy body mover.

I’ll show an pseudo-code example for this, which you could work off:

local Power = ???
RightLeg.Touched:Connect(function(hit: BasePart)
    -- May be terrain, so we check that it is actually an part and not just a BasePart.
    if not hit:IsA("Part") then
        return
    end

    -- Check if hit is actually a ball.
    if hit.Shape ~= Enum.PartType.Ball then
        return
    end

    -- Then apply the impulse:
    hit:ApplyImpulse(RightLeg.CFrame.LookVector * power * hit:GetMass())
end)
3 Likes

That script would go in the workspace correct?
Just clearifying

With a fast moving game like soccer, you are going to need accurate hit detection for your kicks. I recommend using raycast-hitboxing to do this. Once you detect a hit, simply add a bodyforce to your soccer ball.

https://devforum.roblox.com/t/raycast-hitbox-update-3-3-for-all-your-melee-needs/374482

1 Like

I am not using it for soccer. It’s a different type of game. In this game you do not need concistancy with the ball, you just need to get the ball away from yourself.

The code I provided is pseudo-code (well, not necessarily since I still wrote it in a way if you filled out the blanks it’d work); which means if you’d put the code alone it would not work.

You are meant to write your own code based of the pseudo-code.

1 Like

Since its a sphere you could also just do a simple magnitude check lol

1 Like
instance.Velocity = HumanoidRootPartinstance.CFrame.LookVector * 10

What is a magnitude check exactly?

Remember in geometry class where they told u you can find the length of the hypotenuse of a triangle? It’s basically that but in 3d, it tells you how far away you are from a point

function kick(hit)
  local players = game:GetService("Players")
  if hit.Parent == 
  players:GetPlayerFromCharacter(hit.Parent) then 
script.Parent.Velocity = hit.Parent:WaitForChild("HumanoidRootPart").CFrame.LookVector * 10

    end
end
script.Parent.Touched:Connect(kick)

Oh, well this is still a really useful tool you should use. The problem with touch and magnitude is that they are often delayed, unresponsive, or inaccurate.

1 Like

It’s actually the opposite, touch and your custom libraries have delay as they have to do complex math

1 Like

I think a vector force would be good.

this should work tell me if it doesn’t, it doesn’t go up but I’ll find out how to fix that

Workspace.Part.Script:1: attempt to index nil with ‘CFrame’

line 1 is the function, weird?

Wait that was wrong sorry! I am very dumb give me a second lol