Hi Everyone,
First of all I’m very new to coding in general and I apologise if this is a stupid question but I have got as far as I can by myself and would really appreciate a little help, the most basic way you can explain it to me the better. #ExplainItLikeIm5.
I’ve been using Sebastian Lague’s 2D platformer controller tutorials to build my own platformer. Source code here. He bases the controller around using raycast2D to detect collisions. The problem is I’m not sure how to add the ability for the player to shoot projectiles and have them collide with an enemy. The way I understand it is the number of rays and the spacing between them gets calculated initially by the RaycastController.cs script by using the dimensions of the BoxCollider2D and sets up a layer mask. Which is then passed off into Controller2D.cs, and that does the heavy lifting for most things but importantly for collision it does hit detection and recalculates the rays based on the how the player has moved. The PlayerInput.cs script is there to give instructions for what buttons need to pressed to move and jump. The Player.cs script handles how fast the player moves, wall jumping, and all that jazz, and works alongside Controller2D.cs. So in theory I would create an enemy with the same setup for collisions as the player so I would need to RaycastController.cs, I would also need an enemy script to work with the Controller2D.cs to work out an enemy’s position, collisions and taking damage. Then I would need to have a Projectile script to hold damage and remove the projectile once something happens (it travels too far, hits something, hits an enemy). From there I figure I create a game object with a collider2D set to is (trigger) to act as the projectile?
So is my thinking on the right track, I tried this with a rigid body and it didn’t like that I was using addforce to shoot the projectile. Do I not add a rigid body, if so how do I “shoot” it, with transform.position? Sorry for the massive write up I just need to make sure I am at least somewhat understanding because otherwise the advice will go straight over my noob head.
Thank you!