Jump to content
  • Advertisement
standinonstilts

Help with unity 2d Tilemaps

Recommended Posts

decided recently to try to make my first game using unity. I started from scratch and have spent a lot of time figuring out how things learn by myself. I've decided to work on a 2d tile based, top down rogue like and have run into a few issues.

Currently what i am doing is using 2 tile maps: 1 for the ground tiles and the other for the player and enemies (I'm pretty sure this is wrong).

My first issue is when i move my character around the map, a "sprite ghost" often appears in the tile adjacent in the current direction that i am moving.

My second issue is using the mouse to determine which tile i am hovering over / selecting. I want to create a context menu accessed my right clicking which might show things like attack and other actions that can be completed.

Any advice in how to approach these problems would be appreciated.

Share this post


Link to post
Share on other sites
Advertisement

Uploading some images will be useful. The ghost effect could be one of many things.

 

53 minutes ago, standinonstilts said:

My second issue is using the mouse to determine which tile i am hovering over / selecting. I want to create a context menu accessed my right clicking which might show things like attack and other actions that can be completed.

What is the problem here? Unity has a build in mouse event functions.

The context menu would be some kind menu image with buttons and so forth, nothing special. You would either use the Unity mouse down or ray cast to find the context.

 

Please help us narrow down your problems. What did you manage to do so far?

Share this post


Link to post
Share on other sites
23 minutes ago, Scouting Ninja said:

Uploading some images will be useful. The ghost effect could be one of many things.

 

What is the problem here? Unity has a build in mouse event functions.

The context menu would be some kind menu image with buttons and so forth, nothing special. You would either use the Unity mouse down or ray cast to find the context.

 

Please help us narrow down your problems. What did you manage to do so far?

I guess my problem is determining which tile the mouse is over without creating a custom function with tons of variables. I was hoping that unity might have a built in mousedown for the grid component so i could easily get the grid position instead of the mouse position. I tried using raycast but found that the raycast collided even when clicking outside of the game map. I'm new to unity and think that raycasting would be the most practical solution, but I'm not sure I know how to implement it. 

Here are some pictures for the first issue (Player is currently included in the mob list): 

Draw Entities.PNG

Move Player.PNG

1 minute ago, standinonstilts said:

(Player is currently included in the mob list):

I think i may have just found my issue with number one: I'm drawing the player twice? I'll check it out and then update

Correction: Player is not in the moblist, it is just included in another variable called mobmap which keeps track of all the mobs on the map and their locations

 

Share this post


Link to post
Share on other sites
26 minutes ago, standinonstilts said:

Here are some pictures for the first issue

Thanks these actually did help but code can be linked using the "code" <> option in this editor. What I mean by images was your scene; but like I said this helps.

26 minutes ago, standinonstilts said:

I think i may have just found my issue with number one: I'm drawing the player twice?

The whole problem is that your drawing in the first place. You should be moving Unity objects and leave the rendering to the engine.

" rel="external">
 This is a tutorial showing how objects in Unity moves, I didn't watch the full thing but it looks good. It's 3D but 2D works the same.

Here is a grid move script example: http://wiki.unity3d.com/index.php/GridMove

 

To move to a mouse point you just use simple vector math. You get the click point as a vector and move to it using velocity. To find the distance you have to travel just use: MouseClickPoint(capture this) - Player.transform.position.

 

You need to go back to the very basic Unity tutorials before attempting your game. It should be fast for you.

Edited by Scouting Ninja

Share this post


Link to post
Share on other sites

Ok, thanks for the help! Just to clairfy, I should draw the player sprite using a game object instead of a tilemap? (As in, draw once and then move the sprite around afterwards)

Edited by standinonstilts

Share this post


Link to post
Share on other sites
15 minutes ago, standinonstilts said:

I should draw the player sprite using a game object instead of a tilemap?

You can drag object into the scene or you can spawn them. You shouldn't draw them.

Unity has a sprite render or mesh render attached to it's objects. This does the drawing, you don't need to.

https://docs.unity3d.com/Manual/InstantiatingPrefabs.html This is how you spawn a instance.

Instantiate(YourObjectName, new vector3(0f,0f,0f));

You will be using objects and instances.

Hold, I am making a example for you.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!