9 years ago by BennyT
I have a player entity that can pick up other entities (in my sporting game, it is the ball).
the ball attaches itself to the owner and for the time being I am setting the position of the ball entity as so:
however when I go to pass or kick the ball, it doesn't progress because of the collision and the existing logic automatically gives the possession back to the player.
To overcome this situation I change the collision properties when the player entity passes the ball:
however this has presented a new challenge as now no other players can "catch" the ball.
I tried using the .touch() method, as that just looks for any overlap and ignore the collision state but once again, that automatically gives the player that passed possession.
I guess the real question I am trying to understand is how is the best way to handle collisions between entities when they always have to be on screen and not spawn.
I understand things like spawning bullets etc, because you can get them to spawn ahead of the player/weapon entity, but the ball is always in play in a sports game.
Thanks for the help in advance!
the ball attaches itself to the owner and for the time being I am setting the position of the ball entity as so:
if(this.owner != null) { this.pos.x = this.owner.pos.x - 5; this.pos.y = this.owner.pos.y - 5; }
however when I go to pass or kick the ball, it doesn't progress because of the collision and the existing logic automatically gives the possession back to the player.
To overcome this situation I change the collision properties when the player entity passes the ball:
// if the player wants to pass right if(ig.input.pressed('passright') ) { // and the player also has possession of the ball if(this.possession === true) { this.possession = false; ball.owner = null; ball.type = ig.Entity.TYPE.NONE; ball.checkAgainst = ig.Entity.TYPE.NONE; ball.collides = ig.Entity.COLLIDES.NEVER; ball.update("right"); } }
however this has presented a new challenge as now no other players can "catch" the ball.
I tried using the .touch() method, as that just looks for any overlap and ignore the collision state but once again, that automatically gives the player that passed possession.
I guess the real question I am trying to understand is how is the best way to handle collisions between entities when they always have to be on screen and not spawn.
I understand things like spawning bullets etc, because you can get them to spawn ahead of the player/weapon entity, but the ball is always in play in a sports game.
Thanks for the help in advance!