Linearvelocity question

Hello all.

i was working on a RPG (rocket propelled grenade, not role play game) and i feel like im not firing the rocket in the most efficient way.

currently I’m creating an attachment at Mouse.Hit.Position and tweening it to the attachments position. but the orientation of the rocket usually isn’t quite perfect. plus, if something was in the way of the tween, it would just pass through it without exploding :confused: . whats a good way to get an accurate orientation and result?

You should raycast from the rocket’s barrel direction and use where it hits as the hit position. You can then just tween it and it will automatically face the right direction.

i dont know how to use raycast well :skull:. can you give a brief example of how it would be used?

also, if something were put in front of the rocket after it started firing, it wouldn’t hit it, right? i want it to hit.

I would recommend using a library called FastCast. It’s a popular library for gun systems that handles projectile physics and hit detection for you. Using it is very similar to a raycast so it’s also pretty easy to implement. You can find a dev forum post by it’s creator on how to use it and where to get it here.

is it a module or a function? (Max CHarrrr)

It is a module script that you can require in your code using the require() method.

That seems excessive and it would be better to just raycast.

Using a raycast is not suitable when making something like an RPG as its projectiles are affected heavily by gravity and move slower compared to traditional bullets. Raycasts can only travel in a linear direction and are instant. The creator of the post has also stated there is a physical projectile moving within the workspace and as a result of that using a raycast would desync the actual hit detection from the projectile.

OP said he didn’t know how to use raycasts well. It would be better to guide him to a solution, or show him the way to do it rather than to recommend a module for it.

I strongly disagree with that. The point is to guide OP to the correct and intuitive solution instead of the simple one. FastCast is not a complex module. If OP wants to he can implement the FastCast logic himself to achieve the same result but there is no need for that if an already optimized module exists ready to use.

ngl it looks complex to me (max char)

You can find a video on how to use FastCast here.

I agree that there is no need to reinvent the wheel and that FastCast can already do what he wants. The issue with that is he will know how to use fastcast, but not how to solve the issue himself. It is always better to understand how you would go about it manually before using another tool to do it.

OP asked for a solution. I provided him a good one. The point of a reply is not to give OP a lesson on raycasting. Roblox has an entire page on how to use raycasts in games.

I will watch the video when i have time. I believe this is a solution, but i will make sure. thank you for your help. I will mark this as solved if this works.

1 Like

What is your camera system like?

???
default? i haven’t made any changes to it yet

do something like this

local barrelPosition = RPG.Barrel.Position
local direction = -- Something like mouse.hit.position to get the direction to aim the raycast at

local raycastResult = workspace:Raycast(barrelPosition, direction)

This suffers from the same issues I already brought up.

Raycasts can only travel in a linear direction and are instant.

For a simple gun this is definitely the more performant way to do it but projectiles like a RPG aren’t really suitable for this approach.

Yeah, then have the model of the RPG smoothly get to its target, then check if anything with its like blast range, then do damage calculations from there