Getting certain angles

math related question which i failed, how do i achieve an angle projectile shooting like in here


i tried doing this but attempts were useless

Just to get a better understanding, is this for a first person shooter or something of that sort?

something like a magic spell which unleashes orbs in 8 directions instead of straight
i only need to know how to get angles NOT how to make such system for firing orbs.

The orbs would be coming from the player torso or something like that right?

yup
just like in the image
its a player (root if you dont know and live under a rock)
and a base projectile then a direction.
i need to get angles

you could just find out what direction the torso is facing then add a certain amount to that for each angle. since there is 8 it would be in 45 degree angle increments

explain in code please
dkasdkkasd

print("you could just find out what direction the torso is facing then add a certain amount to that for each angle. since there is 8 it would be in 45 degree angle increments")

360/8 is 45 so for every 45* an orb will spawn (8 total). I’ll set the script to run as soon as your character loads in for now, you can customize it however you want. I’m assuming you want it ServerSide, however this is only ClientSide so I’ll leave that part up to you. To determine the angles you will need to utilize basic trigonometry, which in this case Roblox uses radians. Put this inside of a LocalScript inside of StarterPlayer.StarterCharacterScripts.

-- Player references
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

-- If you are using R6, change "UpperTorso" to "Torso"
local upperTorso = character:WaitForChild("UpperTorso")

local numOrbs = 8 -- How many orbs you want to spawn
local radius = 1.5 -- Determines how close the orbs will spawn in adjacence to the player

for i = 1, numOrbs do
	local angleRadians = math.rad((i - 1) * 45) -- Calculate the angle in radians
	local xOffset = radius * math.cos(angleRadians)
	local zOffset = radius * math.sin(angleRadians)

	local orb = Instance.new("Part") -- Random orb customization
	orb.Size = Vector3.new(1, 1, 1)
	orb.BrickColor = BrickColor.new("Bright blue")
	orb.Anchored = true
	orb.CanCollide = false
	orb.Material = Enum.Material.SmoothPlastic
	orb.Shape = Enum.PartType.Ball
	orb.Parent = game.Workspace

	local yOffset = upperTorso.Position.Y - 4 -- Adjusts the height to spawn the orbs at the height of the player's torso

	orb.CFrame = CFrame.new(upperTorso.Position + Vector3.new(xOffset, yOffset, zOffset)) -- Positions the orbs

	local moveDirection = Vector3.new(-zOffset, 0, xOffset).unit -- Calculates the direction that the orbs will move in

	-- A tween animation for the orbs, you can customize this however you'd like.
	local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Linear)
	local targetPosition = orb.Position + moveDirection * 10
	local tween = game.TweenService:Create(orb, tweenInfo, {Position = targetPosition, Transparency = 1})

	tween:Play() -- Runs the tween animation for the orbs
end
1 Like

another question how do you make something like this too

using the same idea but using less rays

how would i make it face the direction the player’s in instead of world direction

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.