I wanna update my now outdated projectile throwing system since it’s very much unrealistic and could be unpredictable, how can I improve it? MouseDir is the mouse position.
Modeling the path of your projectiles using projectile motion principles will help immensely for both realism and predictability.
Since air resistance is by default non-existent in ROBLOX and gravity is always an applied force, all you have to do is calculate the angle and force a projectile is thrown at, and it will, by nature of ROBLOX’s physics engine, be thrown in a consistent parabolic arc.
hence the deprecated uses, like passing parent as second argument on instance creation and debris?
Instance.new(Instance, Parent) is not deprecated, nor is Debris.
Not deprecated as OP stated, but yes, using the second argument of Instance.new()is generally a bad idea.
I don’t think Debris running at 30 hertz (which I think is an artifact of ROBLOX’s 30Hz pipeline which is where the old wait, spawn, delay functions lived) is going to cause serious issues for OP based on their use case. It’s still useful for delayed destruction of items, but you could always use task.delay() to create delayed destruction instead
Hey so I followed this tutorial Modeling a projectile's motion but the velocity was very fast and sometimes the handle would fly upwards when I click on my torso, how do I tone it down?
local GForce = Vector3.new(0, -workspace.Gravity, 0)
local x0 = Character.PrimaryPart.CFrame * Vector3.new(0,2,-2)
local v0 = (Player:GetMouse().Hit.Position - x0 - 0.5*GForce)/2
local Gas = Tool.Handle:Clone()
Gas.Velocity = v0
Gas.CFrame = CFrame.new(x0)
Gas.Parent = workspace.__SPAWNEDSTUFF
I would tone down -workspace.Gravity, as it’s the part of your force responsible for pulling the projectile downwards. Perhaps divide it by a factor of 2 or 4?
Also, it’s flying upwards because that’d be like throwing a ball straight up in real life. You may need to use a different formula or method. Remember, all you need to do is calculate the starting angle and force at which to throw your projectile. ROBLOX’s physics engine can take care of the rest, unless you’re wanting to model the entire path of the projectile yourself.
You forgot to put t to calculate the initial velocity. By varying t you can get different heights.
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local t = 0.5
function onInputBegan(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local GForce = Vector3.new(0, -workspace.Gravity, 0)
local x0 = Character.PrimaryPart.CFrame * Vector3.new(0,2,-2)
local v0 = (Player:GetMouse().Hit.Position - x0 - 0.5*GForce*t*t)/t
local Gas = Instance.new("Part")
Gas.Size = Vector3.new(1,1,1)
Gas.Velocity = v0
Gas.CFrame = CFrame.new(x0)
Gas.Parent = workspace
end
end
game:GetService("UserInputService").InputBegan:Connect(onInputBegan)
just to clarify, this is what the documentation says
When creating an object then setting many properties, it’s recommended to set Parent last
here’s why
This ensures the object replicates once, instead of replicating many property changes
So it is not recommended only for objects that are going to be replicated, for objects parented to Workspace or ReplicatedStorage for example. But if they are parent to ServerStorage or ServerScritpService there should be no problem.
However, if you were parenting your parts to a Model whose parent hasn’t been set yet, then setting the parent first would not matter as the model would not have replicated yet.