I saw this post by @EgoMoose (linked below for anyone needing it). It helped, but his system has a start, end and time, I don’t have an end. I am trying to make a cannon randomly have a rotation, and go a certain distance based on that. How can I do this?
EgoMoose’s post:
This guide was originally written for scriptinghelpers . The original can be found here .
As a somewhat active member of the Scripting Helpers discord one of the most common questions I see is how to have a projectile travel an arc. Most people want to know how to do this for things like basketballs or cannon balls and so forth. Since this is such a popular question I thought it would be worth writing a blog post on it and talking about a few other things we can extend from our findings.
Deriv…
You need to know one more thing, either the power of the cannon or the travel time for the projectile. Is that fine for your use case?
EDIT: Oh, you also need to know the strength of gravity
That seems fine. I can just set a default power how would I go about to do this?
In that case, you can just choose a random start direction. Then the initial velocity is that direction * the cannon power. Just do
local CANNON_POWER = 100
function randDir()
local dir
repeat
dir = Vector3.new(
(math.random() - 0.5) * 2,
(math.random() - 0.5) * 2,
(math.random() - 0.5) * 2
)
until dir.Magnitude <= 1
return dir.Unit
end
ball.Velocity = randDir() * CANNON_POWER
But if you’re not trying to make the ball go to a specific point, then what are you try to do?
The cannon has a random orientation, inside of my limits, and it will prompt users to try to guess where it lands, then it fires and whoever is closet wins