In my game, I shoot particles at high speeds.
This causes two problems.
The particles’ movements are simplified on screen. The actual physics and movement are correct. However, on screen, the particles look like they are teleporting from one position to the next.
This applies to trails I placed on these particles too. For example, if my particle bounced off a wall, the trail shows a curved line between one position before it hit the wall and another position after it hit the wall instead of the actual trajectory it took(hit the wall and bounce off).
Desired Effect:
Actual Effect:
A TriggerCollider I use doesnt detect when these particles enter the collider.
This is a really simple game that only uses colliders and physics2D, and it always runs at 143fps.
The particles move at 200+ speeds(if that is of any help)
I know a little about FixedUpdate and Update, but am not sure how it can help me.
Anyone know any solutions to my problem? I prefer not to compromise on the speeds of my particles.
Thanks in advance
You need to provide more specific details about what a particle is. Rigidbody2D and a certain type of collider? Using a query only (no RB/Collider)?
If it’s a Rigidbody2D and by “200+” you mean 200 world-units then that’s 200m/s so 2/3 the speed of sound.
Regardless, if you’re using a trigger as visualised above, I’m not follow why they even bounce. A trigger won’t produce a collision response. Given the speeds you state, it’s just step over that collider. There’s no continuous collision detection with triggers because they don’t have a contact point.
Can you ellaborate on the components/method used so it’s clearer what you’re doing.
These particles(balls) are Rigidbody2D’s and they bounce off of walls(which is what i tried to illustrate above) and bricks which are BoxCollider2D’s. The interaction here doesn’t cause any problems. The problem isn’t the physics and movement itself, as they move correctly as they should. The problem is that although I get high fps in game, the screen doesnt show the balls moving at that frequency - thus creating the teleportation-like effect.
Would there be other solutions with similar effects to using trigger colliders?
Because physics by default runs at the FixedUpdate. This is described in all the starter tutorials on 2D/3D physics. The default is 50hz as defined in Time.fixedDeltaTime in the project settings.
In 2D you can run per-frame if you wish but there’s things you need to ensure if you do that.
Green Circle: Trigger Collider
Red bricks and black walls: Box Collider
The green circle is meant to be a powerup. So if a blue ball passes by it, I want the green circle to disappear and increment a number in a script.
In the image, you can see every ball passes the green circle without triggering the triggercollider
Sorry, this seems like a completely different subject now.
Previously you were asking about the bounce response, frequency of updates etc. Can we stick to a subject one at a time?
Anyway, it sounds like you don’t understand how Discrete collision detection works on the Rigidbody2D. If you’re moving fast, it’ll just step over the collider. Normally you’d use Continuous collision detection for fast moving Rigidbody2D but this doesn’t work for triggers. Please note that I already said this above.
Also note, the Rigidbody2D has an interpolation setting to provide smooth movement per-frame of the Transform.
For silly high speed you’re best using queries such as CircleCast or Raycast to detect things like triggers.
Yeah there are two problems I want to solve.
One is the frequency of screen updates which can be seen in the trails not correctly following the balls bouncing.
And the other is the trigger collider being skipped.
I feel like decreasing the timestep in project settings and adding interpolation to the rigidbody solved my first problem.
My communication may not have been clear, but I was portraying the two same problems from the start.
If you don’t mind, can you point me in the direction to learning this?
I can but again, it seems you want a setting to fix this so be careful if this is what you’re looking for. It’s simply that your approach is likely wrong. Anyway, here’s how you change it to per-frame. Simply change the Simulation Mode to “Update”: https://docs.unity3d.com/Manual/class-Physics2DManager.html
This won’t stop you tunnelling through triggers necessarily. If you’re travelling at 200m/s then you’ll still move 1m (in a single physics step) if you are at 200fps. 1m is a long distance, easy enough to step over a collider less than 1m in size! Again, this is why you should look at using queries like raycast, circle-cast etc. Cast ahead to see if you hit any of those “special” items. You’ll never miss them no matter what the physics simulation rate is.