How can I script a golf ball projectile?

I’m working on a new project, Blox Golf, which is going to be a golfing range with different games an activities. I want this project to advanced my scripting skills and learn new techniques throughout my experience. My idea for the golfing portion is a camera on a golf ball, with an option to direct the ball to where you want it to shoot and a power bar of how quickly you want it to travel. Additionally, I’d like the ball to shoot forward and up, much like a golf ball would (somewhat similar to a bell-curve graph).

I’m not asking someone to script it for me, because I’d like to do it myself, but my issue is that I’m not sure where to start. If a scripter could guide me in the right directions with different variables and things from the wiki I may need to use, that would be great.

4 Likes

Hi! What you should do is you should get started by reading these articles on User Input Service, what this will do is that it will get you started with knowing how to check player input so you know how to make the power bar work.

Then you can get started with Velocity, what this does is, it will basically help you make it so that you can divide the power with the velocity so that you can control the speed and distance at which the ball goes.

1 Like

Sounds similar to an over the shoulder camera except for a ball instead of the character so check out this article with an example script for that.

Sounds like projectile motion which you can see from this tutorial but with a twist as the ball going up is caused by the ball spinning.

image

You can just simulate this by adding a force going upwards on the ball initially :stuck_out_tongue: so you don’t have to worry too much about the spin aerodynamics physics .

Yeah user input services are the way to go for the power bar as @YellowBannana898 mentions. To record time you can measure time on input began using tick() or os.time() and measure it again on input ended to get the time difference, you can search online for this as it’s similar to making a cool down script.

1 Like

Thank you, @YellowBannana898 and @dthecoolest. I appreciate the help and I’ll be looking into what you’ve both said.

1 Like

And as @dthecoolest said, you should also add negative velocity to the balls forward motion to simulate drag from the air.

1 Like