Thanks for the amazing tutorial. Happy to report it still works, but how and where would you implement "flipping" the X axis of a 2D sprite when moving left/right?
Let's assume your sprite is facing to the right by default, then we want to set the spriteRenderers flipX parameter to true when you are moving left, and false when moving right. For up/down you can just leave it alone and it'll stay whatever way it was. Obviously to do this you'll need to get a referenece to the sprite renderer in your script. The other option is to set the x-scale to negative which flips the game object. As ever more than one way to do things in Unity.
Great video!! How can multiple player movements be implemented? For example, if two players are moving asynchronously, how can they avoid colliding with each other and other obstacles? Thanks
There a bunch of ways you can do this. But ultimately you want a IsThisPositionOccupied() function that you can pass your target location into and it should return True or False. Which you check before calling the move coroutine. How to tell if a position is occupied you have two main ways of doing this. Either you do it with the physics engine. Before moving you cast a 2D ray 1-unit in the direction you wish to move, if it hits another collider then you can't move to it (the issue here is if you have multiple things moving at once and trying to go to the same square). The alternative is to maintain a dictionary of each objects location, that's an efficient lookup that says if the target area contains an item or not. Then you just have to update this each time something moves.
@@FirnoxGames many thanks for taking the time to reply my question. Maybe the dictionary way should be better, I tried in the past with physics and async don’t work very well, sometime players occupied the same position in the grid. Hope you take time and make a tutorial about this new approach because at least in UA-cam I haven’t found how to do it. Thanks!
It is very useful to me! Thank you for your guide!
Thanks for the amazing tutorial. Happy to report it still works, but how and where would you implement "flipping" the X axis of a 2D sprite when moving left/right?
Let's assume your sprite is facing to the right by default, then we want to set the spriteRenderers flipX parameter to true when you are moving left, and false when moving right. For up/down you can just leave it alone and it'll stay whatever way it was. Obviously to do this you'll need to get a referenece to the sprite renderer in your script. The other option is to set the x-scale to negative which flips the game object. As ever more than one way to do things in Unity.
This is such a useful video thanks, however how would one create world borders to prevent the player from leaving the map? Thanks a lot
Thanks for the Video!
Great video!! How can multiple player movements be implemented? For example, if two players are moving asynchronously, how can they avoid colliding with each other and other obstacles? Thanks
There a bunch of ways you can do this. But ultimately you want a IsThisPositionOccupied() function that you can pass your target location into and it should return True or False. Which you check before calling the move coroutine. How to tell if a position is occupied you have two main ways of doing this. Either you do it with the physics engine. Before moving you cast a 2D ray 1-unit in the direction you wish to move, if it hits another collider then you can't move to it (the issue here is if you have multiple things moving at once and trying to go to the same square). The alternative is to maintain a dictionary of each objects location, that's an efficient lookup that says if the target area contains an item or not. Then you just have to update this each time something moves.
@@FirnoxGames many thanks for taking the time to reply my question. Maybe the dictionary way should be better, I tried in the past with physics and async don’t work very well, sometime players occupied the same position in the grid. Hope you take time and make a tutorial about this new approach because at least in UA-cam I haven’t found how to do it. Thanks!