A bit confused regarding the concepts behind the code [SOLVED]

While i pretty much appreciate the course, I am quite confused about the concept of using a shredder and a Rigidbody2D for the lasers over just adding a script to the prefab, that manages movement and destroys the gameObject as soon as it leaves the CameraView.

From what i understand, the “Shredder” Method, destroys the possibility to use a free ratio / playspacesize (unless you place it really high above the playspace, which will result on more laser object and more memory use). - please correct me if im wrong !
Also why are we using the Rigidbody2D, whats the advantage of invoking the Physics engine over just using a method to move the lasers , like the one we use to move the enemys ?

Hello Michael, I can say I am fairly new at game development and have basic programming experiment. But I am curious to learn new things. And I also appreciate this course. In this course I generally try to get things done before watching lecturer’s solution. In the Block Breaker game, there were a smoke clone issue like projectile clone in this game. When I realise it I tried to solve and accomplished it, yeah :slight_smile: My solution for smoke was that I added a script namely “ParticleAutoDestroy” to smoke prefab. It simply checks whether the ParticleSystem alive or not in update() and Destroy if it is not.

As the same way, in laser defender; I added a ProjectileAutoDestroy to PlayerLaser prefab. In script, it finds the uppermost of the camera view [Vector3 upmost = Camera.main.ViewportToWorldPoint(new Vector3(0, 1, distance));] as relative world unit in Start(). And check the position of the “particle” in Update(); if it is leaves the upper edge of the camera view, it destroy particle game object.

if(gameObject.transform.position.y > (ymax + 0.5f)) {Destroy(gameObject);}

By doing this, it makes destroying task independent from playspace size or frame ratio (if I am not wrong about that Camera.main.ViewportToWorldPoint handle that issue itself). And also no need to add Shredder for Destroying particles (Shredder is good solution for the future development when number of game objects increases and game get more complex). But collider for particle -laser- is required for damaging enemy. ı don’t know much about Rigidboy2D and velocity things yet.

I hope you it helps a bit. Have a good games :slight_smile:

1 Like

Thanks Mustafa for the reply,
I did pretty much the same thing in my game, though after looking for a “why does my trigger not trigger” reason in the next lesson, I kind of figured from the Unity Documentation that the BoxColliders won’t work unless you have a rigid body attached, since there is no condition for triggering a collision between two triggers.
So if anyone else is wondering - thats prob the reason.

1 Like

Privacy & Terms