How do i recreate phantom forces bullet trails/tracers?


this is what im trying to do.


(NOT MY VIDEO)

im trying to remake phantom forces bullet trail system. this is what it looks like but i’ve been thinking and i think i mightve figured it out.

image
image
these are pictures of the same object
its just from different angles
but you can see the Shape changes because visually from the camera angle it shows it like that

visually from my camera angle they are not the same length anymore
.
theres a stud length of that
i need to find that length


this is a PHYSICAL representation of this
the green line is what you see VISUALLY from ur CAMERA
I want to know the studs distance of that green line

and then once i get that length i can do a check to see if the length is within a certain range.

you can see at a certain range the beam starts to look like a circle because of the camera angle.

and if its within that range that “looks like a circle” from the camera angle, i can then replace it with this circle and make it face the camera using cframe lookat
image
which will create the nice bullet drop tracer effect that phantom forces has just like in the video.

“?” is an unknown point but it can be made if you get the difference in height between “c” and “b”, and then you can make a point “a”

but then if you keep going straight after “a” then it will intersect segment “d” to “b” which makes a point called “?”

but my question is… how do i get a reference to point “?” because how would I in code, do an intersection like that? making a part and using raycasts to get a intersection point? no im not doing that. thats just bad and i want to do it “mathematically”

the only idea i have to get point “?” is, the position of “a” + the lookvector of “c” to “a” * the distance from “a” to “?” which will = “?”

but how would i get the distance from “a” to “?”

how do i find the length of c to “?”

OR its either im completely wrong about what i came up here and this is not how its done. so please tell me.

5 Likes

This article explains how you can calculate the intersection of 2 lines

Though it’s for 2d, so you will have to make some changes to it.

Then point “?” will be the intersection of line bd and ca, you can ignore the part that stops the lines from being infinitely long in the article.

Only problem I see with this is that the lines need to perfectly intersect, otherwise they will go past each other…

You can use a vector the vectors bc and bd to get a vector projection of bc onto bd to get the ? point.

Screen Shot 2014-12-14 at 12.42.18 PM

In this case, the ? can be defined as projᵥu = (u•v/||v²||)v

In code, this can be described as something like:

-- assuming c, b, and d are position vector3s
local u = c - b
local v = d - b
local projvu = (u:Dot(v)/v.Magnitude^2)*v

Edit: Nevermind, just realized this isn’t what you’re looking for.

this is a good solution but is it the best and only way??? it kinda feels like overkill that i have to remake raycasts

i dont believe they use beams. i’m pretty sure they have a fake bullet model that they use to detect collisions through raycast and when said bullet model moves they tween/cframe it and they have a trail instead. there shouldn’t be any complex math behind a bullet trail if all it does is follow the bullet itself.

however i may be confused on what you’re attempting to do.

image
when you look at it from the back it becomes flat like this

and i was trying to figure out a way to detect this and turn it into a circle

1 Like

i see, its even like that with the FaceCamera bool i assume? i have not done extensive work with trails

yes with facecamera turned on. thats why i wanted to detect this visual difference and then replace it with a circle that uses cframe lookat to actually look at your camera at every single angle

image
like this

What if you used :WorldToScreenPoint() on C and B?

If you set .Z on both of the resulting Vector3s to 0 you could do .Magnitude to get the distance between them in pixels on your screen.

Compare that with how far away the trail is and you can determinate if it should be a circle or not.

1 Like

true true, i saw worldtoscreenpoint and i dont know why i didn’t think of doing that.

i will try that

Sorry, it took some time but I want to redeem myself.

From the description of this post, I assumed you wanted something like this:

To get this, I used the positions of b, c, and d. a is not needed in this problem. For my answer, I’m having the question mark point be the vector v. The vector l represents the displacement of vector b from vector d.

We can get the point v by doing the following:

-- assuming b, c, d are Vector3s
local l = d - b
local t = (c.Y - b.Y)/(d.Y - b.Y)
local v = Vector3.new(b.X + l.X*t, c.Y, b.Z + l.Z*t)

Edit: This is further explanation for what I did, you might be wondering what t is. t is the percentage of c.Y in the interval [b.Y, d.Y]. c.Y is expected to be somwhere in between b.Y and d.Y. Because it is a percentage, t is expected to range from [0, 1]. When c.Y is not in between b.Y or d.Y (meaning t is not in the interval [0, 1]), we get unexpected behavior.

2 Likes



this is me looking at it at “perfect” angles and its almost like phantom forces


its kinda buggy at certain angles viewing it but i think i can figure that out on my own

math is very important for 3d game programming

1 Like


the gif shows it working kinda well at a bit of a far distance but at close distance it doesnt look as good anymore and the way i did it doesnt seem correct.

i dont think what i thought of and what i did is the answer anymore, its more complicated than that

so this isnt as easy as i thought it would be

i ended up using :WorldToScreenPoint() like how @ketrab2004 said but i didnt do it exactly how i was told to. “compare that with how far away the trail is”

im not quite sure how i would compare it like that so im a bit confused but i will try to do that next somehow?

but anyways thats not what i did, i used 2 beams and compared their pixel magnitudes to determine if it should show as a circle… when it appears that you are looking at the “back” or “front” of the tracer it should appear as a roundish shape, and if you are looking at the sides it should look elongated.

this video shows exactly what i mean:

[Not my video]

so im trying to figure out how to re-create this

3 Likes

When you use :WorldToScreenPoint() the distance between the points changes based on how far the bullet is. So if you only check the distance between the points the trail will become a dot when it’s far away, even though you are looking at it’s side.

That’s what I meant but thinking about it I think it wouldn’t make much of a difference, since it’s already so small on the screen.


I’m not quite sure what you want to re-create exactly, but if it’s something new/different you should probably just make a new post.