Best way to render bullet tracers?

Ok there’s an interesting development. When i hit someting a distorted cone appears on the screen. But it’s not moving, it just stays there

I’m afraid we are not creating what you expect to create. If you read the main question of this topic, the user ask for a drawLine alternative.

I guess you try to create something like I did below? If so, then you can create this in the editor and clone this everytime the player shoot.

image

The title of the topic is “Best way to render bullet tracers”. Creator of this topic wanted to do the same thing i do. I don’t think the result i get is what the creator of this topic intended to do bcs this doesn’t achieve anything. Yes i try to create something like that shown in the ss. But that object needs to move with the raycast, is that how it works in that project?

My interpretation was that the user wanted to create something like below.

g2-vip-glow-ammo-tracers

The entity moves independently of the raycast, but the player of the game doesn’t know this.

I mean it looks fine but i need to see it in motion. It looks more like a laser beam than a bullet. It’s an infinite line, and i don’t know if it gets disappeared after a time the gun is fired.

“The entity moves independently of the raycast, but the player of the game doesn’t know this.”
So you move that object with rigidbody like this: “bullet.rigidbody.applyImpulse(this.force);” ?

That’s a possibility, but I use a kinematic rigidbody so I don’t use forces.

https://developer.playcanvas.com/en/tutorials/manipulating-entities/

can i synchronize the timing of the bullet hitting the object with the raycast’s hit with this method?

I don’t think so.

Ok let me understand this please, is it possible to fire a visible projectile along the line of raycasting. Like you do in kinematic rigidbody or applyforce? This is what i have to do, i need to move that projectile with raycasting

A raycast is instantly while a visual bullet moves over time. You can move the bullet over the same line as the raycast, but they will not reach the end at the same time.

Then how other FPS games are handling this? Or they don’t, the player’s aren’t noticing this bcs there’s a very little time duration with the impact of the bullet and raycast’s hit?

I think it depends on the type of game, but for my game I use the raycast to determine the hit and use the visual bullet to make it looks nice. You can also use collision detection on the bullet entity and skip raycasting, but there is a possibility the collision is missed because of the high speed.

1 Like

@Ronin I don’t want to muddy the waters but I think it may be possible to move a particle system from the raycast start point to the end point of the raycast tapering off the visibility toward the end. I have seen this done before in other games but have not yet tried it. Otherwise I think @Albertos idea above does look visually correct based on the question.

“but there is a possibility the collision is missed because of the high speed.” that’s the whole point i switched to raycasting. I was using forces to handle the shooting before and no way i could hit a moving object with that. Yaustar highly reccomended me to use raycasting for a FPS game and i also learned that raycasting is the most ideal method for a FPS game. I’ll stick with raycasting

If you had a video example from another game to help communicate what you would like the effect to be, that will help a lot

In unity they handle it like this:

 if (Physics.Raycast(ray, out hit))
            {
                Target = Instantiate(HitPoint, hit.point, Quaternion.identity) as GameObject ;
                Bullet = Instantiate (Spell, gameObject.transform.position, gameObject.transform.rotation) as GameObject ;
                Bullet.transform.LookAt (new Vector3 (Target.transform.position.x, Target.transform.position.y, Target.transform.position.z));
                //Timer = TimerAmount;
            }

They also use the trail renderer component of Unity to render the bullet trails. They use particle effects for muzzle flash and bullet hole decals generally

not a game video but a Unity tutorial: Add Bullet Tracers to Your Hitscan Guns | Raycast Shooting Unity Tutorial - YouTube

In that video, they have bullets that travel a distance over time.

The way I would do this is to have either bullet entities or something that manages bullets in the world.

When the player fires, it creates a bullet and every frame, it moves at a set speed in the direction the player is shooting in. It would also raycast from the position it was in last frame to it’s new position this frame.

This solves the fast moving rigidbody issue where it can go through objects.

Then you can have your trail do whatever you want behind the bullet

1 Like

Ok, so you’re basicly saying the same thing with Albertos, i should fire the bullets not with raycast but with another method right? Raycast will be used to deal damage while bullets are just for visual effect and they’ll be fired with another physics method. If you think this is the way to go in Play Canvas then i’ll go with your way

No, you should fire bullets with raycast, just not over the WHOLE distance in a single frame

1 Like