So, my plan is to create a projectile which will send sparks flying off at an angle when it hits something. So far I got this. It works fine, but there is a lot of clipping, unfortunately, which I need to get rid of.
My first idea was to calculate the angle between the reflection lookVector and the normal, and determine a range of spray from that, although I then realised that my angle would only work on a 2D level, and I'd need to take into account the other components.
So now we come to my final idea. I'd like to find the CFrame at the point of collision, facing down the surface in the direction of reflection, in-line with the surface normal. Here are some images below to help you understand.
I'd like the CFrame of the red part...
Green = Surface normal Yellow = Path of projectile + Path of reflected projectile
https://gyazo.com/e87d7dea4d627dbb3bdee515a4af18a6
https://gyazo.com/1d013c2a8f2269e5e816ea25ebad5ff0
I can give you the normal [lookVector], the direction of reflection [lookVector] and the position of collision [Vector3].
I am happy to answer any questions people have about this.
Not sure if I'll be able to explain this in proper depth, but I think I got an idea.
You could construct the CFrame completely from scratch by using some vector math. To be specific, you could get all the vectors you need via 2 cross operations.
First you have to understand that CFrame is made up from 4 vectors. The position, top unit vector, back unit vector and right unit vector. So in theory, if I figure out these 4 vectors, I can create a CFrame from scratch.
The cross product of two vectors is another vector, which will always be perpendicular to the previously mentioned vectors. Using this property, I can figure out rest of the unit vectors necessary for CFrame.
local normal, reflection, pos local right = reflection:Cross(normal).unit local back = right:Cross(normal).unit local cframe = CFrame.new(pos.x, pos.y, pos.z, right.x, normal.x, back.x, right.y, normal.y, back.y, right.z, normal.z, back.z)
Edit: Fixed 'Cross'