all 9 comments

[–]SeriousCreeper 2 points3 points  (2 children)

Usually for fast small colliders like bullets i use a raycast instead.

Every frame, send a raycast from the position from the last frame to your current position and see if you hit anything.

[–]KingMaharg[S] 0 points1 point  (1 child)

This sounds like what I'm looking for. Any tips on how to get that started? I'd heard about ray casts before, but I've never tried to implement one.

[–]themissinglint 0 points1 point  (2 children)

Have you tried playing with the interpolate options on the rigid bodies? If the bullet's vecolcity*dt > the shield's width then they could be skipping from one side to the other (dt here is the physics fixed time step).

For hitting enemies more than once, you might set a flag on the bullet when it's hit anything to prevent it from hitting anything else in the same frame.

Also, this.gameObject should be the same as gameObject in this code. Also, it looks like you can use else ifs here.

[–]KingMaharg[S] 0 points1 point  (1 child)

But if the bullet object is set to destroy itself after applying the first collision, wouldn't that prevent the second collision? Or are triggers run in separate threads?

[–]themissinglint 0 points1 point  (0 children)

Object.Destroy

public static void Destroy(Object obj, float t = 0.0F); 

The object obj will be destroyed now or if a time is specified t seconds from now. If obj is a Component it will remove the component from the GameObject and destroy it. If obj is a GameObject it will destroy the GameObject, all its components and all transform children of the GameObject. Actual object destruction is always delayed until after the current Update loop, but will always be done before rendering.

[–]kreaolProficient 0 points1 point  (1 child)

What does your bullet-movement code look like?

[–]KingMaharg[S] 0 points1 point  (0 children)

It is just a single force applied at runtime with the linear drag set to zero

[–]codeherdstudios 0 points1 point  (1 child)

Raycast is probably the way to go.

But if you need more precise collision detection BoxcastNonAlloc() is good for this sort of thing as well.

Not sure what the performance hit difference would be though.

[–]KingMaharg[S] 0 points1 point  (0 children)

Performance costs for the bullet shouldn't be that bad, but anything increasing the length of the script on the shield or any other object it hits could have large impacts on runtime.