Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

model a projectiles motion?

Yes I have seen THIS post It does work but if you move the mouse far away (e.g space) it shoots it extremely fast the code that calculates it:

	
local hrp = game.Players.LocalPlayer.CharacterAdded:Wait():WaitForChild("HumanoidRootPart");


local t = 1

local g = Vector3.new(0, -game.Workspace.Gravity, 0);
local x0 = hrp.CFrame * Vector3.new(0, 2, -2)
-- calculate the v0 needed to reach mouse.Hit.p
local v0 = (mouse.Hit.p - x0 - 0.5*g*t*t)/t;

I'm wondering how I can slow it down, (there's a max speed, e.g 25 studs/s)

GIF of it going very fast

Note: if you know of any better ways of doing this please say (e.g raycasting or something like that)

1 answer

✓ Accepted answer

You could limit the velocity like this

local v0 = (mouse.Hit.p - x0 - 0.5*g*t*t)/t;
v0 = v0.unit * math.min(v0.magnitude, MaxVelocity)

This discussion is preserved as it was. New answers, comments, and votes are closed.