Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Avarthar · Feb 02, 2021 at 08:25 AM · 2dcollisionmovementtilemapisometric

2D C# isometric Tile-based movement and collision problem

Hi, I am having a little bit of trouble trying to make my character collide with other sprites like walls or simply stopping it from going outside the tilemap tiles whilst allowing for multiple floor levels.

- How should I go about doing so?

The floor level part I already have a good idea how I will manage it, but I have already tried fixing the collision part over the last few days and so far this is the only thing stopping me from advancing my project further.

The movement itself works great and without any problem so far. I simply cannot figure out how to make the collision work.

- What I tried already:

  • Having the player use a Rigidbody2D with gravity set to 0 and a tilemap collider on the tiles. -- Worked-ish, but was far from what I would want. For some reason going into a wall makes the character bounce back since the position the character tries to move onto would end up in a collision loop. I did combine the collisions as to reduce the performance load and manage to make the collision boxes be actual boxes and not weirdly formed and it still had that problem.

  • Detect if there is a Tile in the direction the Player Character is moving towards. -- I could not figure out how to detect the specific tile through the C# script itself.

- The Way I have my script setup:

(Excluding the Collisions since I removed the failed attempt I had to keep my code cleaner. But put simply I tried to get the tile and if its type was null I would not allow movement, but I cannot figure out how to get said specific tile type at the direction position)

  • I do have the tilemap put into a variable if this helps out in anyway to get the specific tile type. And since I cannot input a float into the method it has to get the tile, I have no clue how to do it.*

-- The way I send the movement if (Input.GetKeyDown(KeyCode.W)) { direction += new Vector3(1.0f, 0.5f); }

-- The way I make the character move MoveCharacter(Vector3 dest) transform.position = Vector3.MoveTowards(transform.position, dest, movementSpeed * Time.deltaTime);

I would greatly appreciate any help towards making this collision work, thank you in advance for your answers.

Update to the question: I have managed to make the up and left collision work, but for some reason it does not work when going down or right. I am currently using the 2D Raycast method.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by unity_ek98vnTRplGj8Q · Feb 02, 2021 at 11:42 PM

Use Rigidbody2D.MovePosition() instead of setting the transform.position directly. If you set transform.position directly it will move your character without regard to any colliders or physics calculations, then the physics system will try to fight that position afterwards which results in the character bounce back. Rigidbody.MovePosition checks colliders while it moves. You may also want to look into the CharacterController script which can help solve some of the weirdness of rigidbodies.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Avarthar · Feb 03, 2021 at 02:02 AM 0
Share

Huge thank you for the suggestion! Having an actual contact point to deter$$anonymous$$e if the character can move towards that point or not helps a lot. And as you said, the physics works super great using Rigidbody2D.$$anonymous$$ovePosition() instead. You are an absolute legend <3

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

344 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Best way to spell hit a target 2D tile based game. 1 Answer

How to highlight only walkable path on tilemap,Sorting walkable path on a tilemap 0 Answers

Tile palette not arranging correctly 0 Answers

How do I set up my sprites/skeletons to correctly interact with isometric sorting layers? 2 Answers

2D Isometric Movement Path (8 Directions) 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges