How can I make a raycast arc in the path of a particle?

So I have a particle emitter, and I want to make a series of raycasts in an arc in the path of the emitter. I know it can’t calculate the randomness, but with the amount of particles, the randomness doesn’t even matter.
So the emitter is a cone shape with a 15 degree spread. I just need a raycast arc that can fit anywhere in the spread, with the same gravity and speed and whatever.

1 Like

You could use shapecasts and make a MeshPart roughly the size and gravitational curve of your particle ‘fountain’.
It would do everything you are asking in your post except for changing the curve for gravity if your ParticleEmitter Part is tilted up or down.

3 Likes

well the “fountain” is gonna be moving a lot so like
the red is the particle emitter cone and the blue are any possible raycast arcs

2 Likes

But is the fountain tilting up and down at different angles? That’s the only thing that would make gravity affect the shape.
If the Part in your image is moving horizontally or vertically and only rotating around the Y axis then the MeshPart could be shaped just like your red outline and work just fine.

2 Likes

yes the fountain is going to moving all around, and I can’t use shapecasts, is preferably has to be raycasts

2 Likes

You can use this function I made to raycast alongside a projectiles motion.

I also suggest using EgoMooses beam function to visualize it.

--g gravity, v velocity, t time, p initial position
local function projectileMotionEquation(g, v, initialPosition, t)
--See Ego Mooses tutorial on integrating projectile motion equation
	return 0.5 * g * t ^ 2 + v * t + initialPosition
end

local function raycastAlongQuadraticPath(g, v, initialPosition, endTime, raycastParams)
	local segments = 10*math.round(endTime*3) -- based on default beam adjust if needed
	local timeGapIncrements = endTime/segments

	local currentTime = 0
	for i=1, segments do
		local point1 = projectileMotionEquation(g,v,initialPosition,currentTime)
		local point2 = projectileMotionEquation(g,v,initialPosition,currentTime+timeGapIncrements)
		local direction = point2-point1
		local rayResult = workspace:Raycast(point1,direction,raycastParams)
		if rayResult then
			return rayResult
		end
		currentTime += timeGapIncrements
	end
end

4 Likes

What is the t/time variable for? What do I plug in there? and also end time?

I get this error
Workspace.Script:81: attempt to perform arithmetic (add) on number and Vector3
on this line

return 0.5 * g * t ^ 2 + v * t + initialPosition
1 Like

FastCast makes a bunch of rays in an arc, simulating gravity.

useful function, saving this for later :+1:

1 Like

Is this just a visual effect or will it actually apply some sort of damage?

I get you understand what ‘moving all around’ means to you but if you ask 10 people what ‘moving all around’ means you’d get 10 different answers. Some would mean ‘moving in the x & z axes but pointing in the same direction’, others would say ‘rotating around a specific point in a circle but not tilting or moving’, others would say ‘moving and rotating in all 3 axes like a helicopter’.

I’m not trying to sound like a PITA, but the reason I ask specific questions like “is it tilting up and down” was to give everyone an answer that explains what you mean without anyone having to assume what you mean is what we think you mean.

3 Likes

The part will be moving in every axis, flailing around like an arm if you catch my drift.
I tried to chatgpt my way through it but the dumb ai doesn’t know how to code.
I got kinda close, but not exactly. The last code I used from it only worked right if the fountain was facing the top or bottom, but when I angled it like in the picture, it didn’t really work right.

1 Like

none of this works btw, like, you tried to put a number (point1) where a vector 3 should be.

3 Likes

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