Hello! I am currently trying to make a system which kicks a soccer ball whenever you press “e” I have been looking for a solution to this for a while, but I have not been able to find one. Does anyone know a way this is possible? I’ve tried using tweening to find a way to move it, but i still have not been able to do this successfully. I already have a piece of code to execute the movement, i just want to know how to do the movement.
local plr = game.Players.LocalPlayer
plr:GetMouse().KeyDown:Connect(function(k)
if k == "e" then
--what do I put here?
end
end)
I can only think of is If you are further away from the ball’s magnitude then the higher the distance the lower the velocity but lower the distance the more
velocity value of your kick
And tbh Idk how to do that sorry
This is what i have currently, Is there anything wrong? My sound won’t play in it doesnt look like the ball is moving.
Ball = game.Workspace.Part
local animationTrack = game.Workspace.Part.kick
local Player = game.Players.LocalPlayer
local sound = game.Workspace.Part.Kick
local function Sound()
if not sound.IsPlaying then
sound.Play()
end
end
game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.E then
if (Player.Character.HumanoidRootPart.Position - Ball.Position).Magnitude < 5 then
Ball.Velocity = Vector3.new(2,2,2)
animationTrack:Play()
Sound()
wait(0.1)
Ball.Velocity = Vector3.new(1,1,1)
end
end
end)
Correct me if I’m wrong, but I’m not sure you can set velocity. What I would suggest is creating a BodyVelocity with your velocity and Destroy()ing it after about 1 second. Also, it looks like the ball would only move in a single direction with your provided script. I would suggest getting Player.Characrer.HumanoidRootPart.CFrame.LookVector*num where num is your desired velocity. That way, the ball will move the direction the player faces. Hope this helps!
Whenever I press e, nothing happens, and the sound still does not play. I have the sound under the part and the animation is there too, but doesnt happen either. The ball when touched just flies into one direction at high speeds
My bad for not giving a better explanation to what I want, because currently the ball isn’t working. I want a GUI that is above the ball whenever you are close to it. The GUI will simply just have the letter E on it. Whenever you press E, the ball will move on itself, not on user impact. I also will implement a sound and an animation to go with it. If anyone has an idea on how I could fix this, please let me know!
Changing the Velocity property of the ball manually based on the direction you intend to kick it in. Example: Ball.Velocity = Character["Right Leg"].CFrame.LookVector * 10 -- 10 is the power you prefer
You can make use of BodyVelocity instance that is parented to the ball for movement. You can adjust the properties similarly to the first point mentioned. You can combine this with using the service Debris, so you can destroy the instance after a prefered time. Example: game:GetService("Debris"):AddItem(Instance, Time)
These would give you the desired results making use of physics. However, if you attempt to do this on your client alone, you would need to be the NetworkOwner of the part. This would not work if you are not, unless the ball you created is through the client. So you would need to communicate with the server via the use of Remotes to make the changes needed to make it possible.
You should also consider using a hit box method such as: Touched, Magnitude, Region3, Raycast to register the hit and carry on the physics functions.
Also a correction to your Sound function needs to be made. It should be sound:Play() instead of sound.Play()
You can try making it a handle. Make a script in ServerScript and add a module in it and have all the maths in the module. If you need me to script it for you I will