How would I go about kicking a ball?

      I am trying to make a ball where, if the player touches it, the ball will kick forward like a soccer ball. I set all the CustomPhysicalProperties to 0 but I'm not getting the results I'm looking for.

Dev forum pic 1
I’m looking for the ball to kick like this:
image
If someone could help me it would be appreciated.

3 Likes

Sorry for how this is written, this is my first post.

If you tell when the player touches the ball you can apply a force to the ball in the opposite direction of the player

1 Like

How do I apply the force? Would I use:
Vector3.Velocity

Maybe BodyVelocity or just instance.Velocity

You could use a body force or just add to the velocity of the ball

Would you mind explaining further? I’m a little bit new to scripting

Add a .Touched event to each of the player’s legs and if part it hit is the ball then Ball.Velocity = Ball.Velocity + CFrame.lookat(Leg.Position, Ball.Position).lookVector * Force
this is not exact code as it probably has syntax errors but it is a start

As the player touches the ball, save the velocity of the players part that touched the ball, and then considering it give velocity to the ball in the opposite direction. You may use BodyForce but this thing is somewhat laggier than simple velocity.
Btw, there is some stuff with Custom Physics Properties in the part properties, you might wanna have a look.

2 Likes

How would I go about having a function connected to the player’s legs that causes the ball to launch forwards? Can I tell the ball to function onHit, or is there more to that? I also dont know if I want to have it only function when it hits the legs, I think it would be better for me if the ball would go forward no matter where you hit it.

1 Like

player.Touched:Connect(function(hit)

end

1 Like

something like

part.Touched:Connect(function(PartToHit)
     local velocityOftouched = PartToHit.Velocity
    --apply the velocity
end)
1 Like

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