Hey, it’s me Army, and today I’m asking another question.
So lately, I’ve been trying to make somthing that players can throw, I’ve planned most of the script, but what I cannot find out is how to make the part thrown.
I have, as you should when making a post, have also looked for a solution. One of them was what I was looking for, but it had a target. I looked at BodyVelocity, but the movement is constant force, while I’m only looking for a short pulse, similar to an object in a slingshot.
No target, no constant movement. Just trying to get a part to go in a short throwing motion.
Like last time, any help is appreciated, and I would defenetly look at all of the comments, as a lot more are useful other than the one i put as the solution
what you can do is use body velocity, but while it isn’t active set the max force to vector3.new(0,0,0) and while it is have it as something above 0, you can set it to 0 again a little bit after you throw it so that its not constant anymore.
This is just done in a local script, you will need to modify it to work in your situation. This will fire a part in the direction of your mouse.
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local mouse = player:GetMouse()
mouse.Button1Down:Connect(function()
local part = Instance.new("Part")
part.Size = Vector3.new(1,1,1)
part.CFrame = character.HumanoidRootPart.CFrame * CFrame.new(0,3,0)
part.Parent = workspace
local direction = mouse.Hit.LookVector -- get the direction we want the part to go in
local forceMultipliter = 100 * part:GetMass() -- we get the parts mass to make sure that if the part is bigger or smaller it will still go about the same distance
part:ApplyImpulse(direction * forceMultipliter)
end)
You will need to make changes so that it fits with the rest of your game. If you are storing the players elsewhere (such as a model in workspace) then yes, you will need to change that. Because this is also in a local script, only you will be able to see the part fired. If you want for other players to see the object then you will have to work with remotes.
If you were to upload a game with only a local script with the code I sent before in it and you were to get others to join, only the person “throwing” the parts would be able to see their parts (aka the parts don’t replicate). If you want everyone to be able to see the parts, you will need to work with remotes.