Handling Projectile Movement

I am working on a Bow tool and I need it to shoot arrows that don’t just go straight but have gravity actually effect it

Right now I have a tween solution that tweens to the end
I have no idea how else to do it

Ideas?/

1 Like

why not use FastCast instead?

1 Like

I think you misunderstood
I am not trying to detect a hit
I am trying to figure out the path for a arrow and how I should move it along the path.

1 Like

What I suggest is get the direction first basically like if you’re clicking somewhere to where you want to the arrow to shoot at it can be defined as the end position then you get the start position which is where the player is at or the bow, subtract the end position by start position define it as direction then make a variable called force and make it equal the direction + vector3.new(0,workspace.Gravity/2,0) then lastly for the arrow just do arrow:ApplyImpulse(force * arrow.AssemblyMass) since I’m not on pc rn couldn’t give a code sample but what this does is instead of making it shoot straight it’s gonna get affect by gravity so it’s gonna go up in a curve then back down being affected by gravity.

Or you can just learn more about it and get what you’re looking for in this video he does a very good job explaining something similar of what you’re talking about if not exactly. Surprisingly I watched it earlier today and made something from what I’ve learnt

you will probably have to use trig

I have 2 variables
power(how strong, 0.5-10, based on how LONG you pull back)
and direction
nothing else
I want the bow to not just have perfect aim lmao I want it to actually require aiming, no just set end position

what do you mean by trig what is that??

Hello. I hope this is helpful. To simulate projectile movement using only power and direction, you can do it in two ways:

  1. Using Roblox physics
  2. Programmatically

If you’re using Roblox physics, then it’s like this:

  1. Create the Arrow. It should be an unanchored BasePart.
  2. Move it to the launch position. This is probably in front of your bow.
  3. Use CFrame to orient it to the direction you determined.
  4. Use BasePart:ApplyImpulse() in the direction of force, multiplied by the power.
  5. Connect to the Touched event to see where the arrow hits.

That’s the straightforward approach, although rather naïve. If you do that you might notice that it’s not really the best way to go about it, especially if you want a reliable way to fire arrows. You’ll end up having to deal with somewhat weird collisions, and there’s also NetworkOwnership and security because of how Roblox handles physics replication.

So I suggest doing it programmatically, this involves some more advanced scripting. You will use something called Raycasting. Ideally, you can just use FastCast to avoid doing the heavy lifting of scripting the system yourself. There’s a very helpful tutorial (here) showing you how to do it. It’s a tutorial for a gun, but you can easily just use a Bow model and an Arrow for the bullet, tweaking the Velocity value to be your Direction * Power.

But to complete my answer here and guide you with how to do just that, here:

  1. From the start point, you’re going to raycast a short distance, this would be in the direction of launch and the distance would be how far your arrow can travel in 1 frame. Usually this is done as a function connected to Heartbeat() or RenderStepped().
  2. Check if the ray hits anything. If it does, then handle the hit – you’re going to process doing damage here, and probably welding the arrow to where it hit. If it doesn’t, then raycast again, but this time from the end of the first cast, and the direction would be affected by gravity and would point lower down. If you’re just using vector directions, this can be done by adding a Vector3.new(0, -workspace.Gravity * DeltaTime, 0) to your direction vector.
  3. Keep doing that until you reach a maximum number of iterations, or until the arrow hits something.

Also, trig means trigonometry. You may need it when calculating the projectile motion, depending on how you’re getting the direction of launch.

well i guess you could just send a lot of rays, each one going slightly lower than the previous one until its going straight down. kinda like fast cast does it.