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 . 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 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.
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.
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.
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)
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