Here’s something that I have been working on the past few days. It’s been an issue getting all the math correct. But here’s the video: Showcase for a working catapult in Roblox.
The original model came from the toolbox. Credit to @Mister_Robloxer2020 for the model. I took their script and heavily modified it. Added many new features and cleaned up the code. I also hinged the arm so the animation is physics based so it doesn’t use an animator. When it launches, it launches flaming rocks that explode when they land.
As for the controls, one can set the direction, elevation, and power. The directional and elevation controls take into account the orientation of the catapult. So at 0°, it fires in line with whatever direction the catapult is facing. The elevation controls the angle in which the projectile is launched at. The power setting controls the amount of force that the projectile is launched with. More force means more distance. The vertical sliders were adapted from a YouTube tutorial found here: Roblox Studio - HOW TO MAKE A SLIDER GUI. The dial slider was adapted from that tutorial with my own creativity in getting it to work.
One thing that I want to add is a target marker so the player using the controls can see approximately where the projectile will hit without all the trial and error to dial it in. I also want to show the approximate flight path the projectile will take when it’s launched. Not entirely sure how to do that though. I’m thinking of using the formulas for Newtonian Mechanics from physics.
The formulas for projectile motion is as follows:
`y(t) = -0.5at^2 + vyt + y0`
`x(t) = vxt + x0`
Where the following parameters are defined:
y0: Initial y position
x0: Initial x position
vy: y velocity component
vx: x velocity component
a: gravitational acceleration
t: time
So, what do you think? Comments? Suggestions?