Jump to content
  • Advertisement
ethancodes

Algorithm examples of how pickups are handled

Recommended Posts

Hmmmm this is closer I think but it's not always the Paddle it will collide with, sometimes it might be the ball. If I made the PowerUpManager static and put it on the ball and the paddle, would that male it so it would all track in one place no matter which object the pick up hits?

Share this post


Link to post
Share on other sites
Advertisement
1 minute ago, ethancodes said:

Hmmmm this is closer I think but it's not always the Paddle it will collide with

Then just add two collisions or do an or check.

if(col.gameObject.name == "Player1" || col.gameObject.name == "Ball")

Other possibilities is to give the ball and the player the same tag. Moving them to the same layer also allows for layer checks. You could even add a variable to the objects and check for it on collision.

There really isn't a way around this; you will always make more code the more you need to do.

 

With that said, learning the observer pattern is a good thing if you want to try it just to learn. You will use it a lot in complexer games. It's just that most of the code Unity uses already follows this pattern.

Share this post


Link to post
Share on other sites
Posted (edited)

I really want to learn the observer pattern, however I think I found a solution that is going to really cut out a lot of code, so I'm going to go with that. 

Edited by ethancodes

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!