Create a 2D grid movement player controller script in Unity

  Рет қаралды 3,940

Firnox

Firnox

Күн бұрын

Пікірлер: 8
@moriyainstitute990
@moriyainstitute990 4 ай бұрын
It is very useful to me! Thank you for your guide!
@gerarddilk4862
@gerarddilk4862 11 ай бұрын
Thanks for the Video!
@mistycomet7501
@mistycomet7501 Жыл бұрын
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
@user-ve9xq7le5y
@user-ve9xq7le5y 6 ай бұрын
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?
@FirnoxGames
@FirnoxGames 6 ай бұрын
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.
@mnicodev
@mnicodev Жыл бұрын
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
@FirnoxGames
@FirnoxGames Жыл бұрын
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.
@mnicodev
@mnicodev Жыл бұрын
@@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 KZbin I haven’t found how to do it. Thanks!
Let's Create: Asteroids in Unity
31:59
Firnox
Рет қаралды 5 М.
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 16 МЛН
2048 Nasıl Yapılır? (Unity)
1:10:31
Bilal Emre Gürkan
Рет қаралды 5 М.
I Made the Same Game in 8 Engines
12:34
Emeral
Рет қаралды 4,3 МЛН
Unity's New Input System:  The Definitive Guide
32:07
DmanGames
Рет қаралды 34 М.
Every 2D Node Explained in 9 Minutes !
9:19
Lukky
Рет қаралды 380 М.
Why is unity so slow!
5:53
Jason Storey
Рет қаралды 72 М.