Hello, I am trying to design a grenade-like system. Basically, wherever a player clicks, an explosion will be placed. I am using the humanoid target point of a tool as the position for the explosion.
The issue is, the explosion can happen anywhere you click, but I need to factor in range. I have tried many things, but they aren’t working. (If I could only place something at the end of a ray this would be super easy…).
Whenever I run this current version and throw an explosion out of range, the explosion occurs around the center of the map.
--calculate explosion's position within range
local bombPos
if (target - plr.Character.UpperTorso.Position).magnitude > gameSettings.BombThrowRange then
bombPos = (-(target - plr.Character.UpperTorso.Position)).unit * gameSettings.BombThrowRange
else
bombPos = target
end
Thanks!