How would I make specific bullet patterns, some targeting the player, some going in random positions inside a battle box?

basically what i want is to make bullet patterns similar to undertale, where they either target the player, they go into random positions or they follow another pattern.

this is what i have already:

this is what i aim for:

2 Likes

i have made another topic about this, but that was about the whole system, whereas this concerns just the bullet patterns :>

1 Like

It’s like logic of:
Math.Random, 1 or 2 or 3 (like first player, second random position, pattern’s vector)

If one then
It says self it
End
If two then
You random the vector
And make sure it’s not outside of the battle box

By cacluting vector(-s) of it

If three then
Get pattern’s vector and each patterns until reachs end

So i just saw the video (it’s actually complicated than this…), i couldn’t think better

2 Likes

okay this is a really good solution - thank you so much, but how would i calculate the vector boundaries of the battle box (sorry i’m really dumb at times)

Just get a random vector or something and either does this:

p1:GetClosestPointOnSurface(randomVector)
p1 being a part(Invisible Part with No canCollide) or also do a random Vector and do this:

local function clampToPartInterior(position: Vector3, part: BasePart): Vector3
	-- Convert world position to part's local space
	local localPosition = part.CFrame:PointToObjectSpace(position)
	
	-- Get half size of the part
	local halfSize = part.Size / 2
	
	-- Clamp to the part's bounds
	local clampedLocal = Vector3.new(
		math.clamp(localPosition.X, -halfSize.X, halfSize.X),
		math.clamp(localPosition.Y, -halfSize.Y, halfSize.Y),
		math.clamp(localPosition.Z, -halfSize.Z, halfSize.Z)
	)
	
	-- Convert back to world space
	return part.CFrame:PointToWorldSpace(clampedLocal)
end

So no matter what the random vector is, its always clamped inside

1 Like

I just realized, that means most of the things are on the edge, revised code:

local function getRandomPointInPart(part: BasePart): Vector3
	local cf = part.CFrame
	local size = part.Size
	
	-- Generate random offset from center
	local randomOffset = Vector3.new(
		math.random() * size.X - size.X/2,  -- Random X within bounds
		math.random() * size.Y - size.Y/2,  -- Random Y within bounds
		math.random() * size.Z - size.Z/2   -- Random Z within bounds
	)
	
	-- Convert to world space
	return cf:PointToWorldSpace(randomOffset)
end


This should calucalte on the inside

1 Like

thank you so much :DD
i’ll try this when i have the chance

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