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
1
Question by Raithen · Mar 14, 2014 at 06:36 AM · 2dcollisionspritemaze

I drew a 2d Maze. How to collide with walls.

Hi,

A top down game where I move a guy through a maze. I drew a maze in paint and imported it in as a sprite (think pacman looking level)

I couldn't think of a way to make my player trigger events when colliding with the walls. I cant use 2d polygon collider as it tries to look at the sprite as a whole.

Ways I've thought, but I thought I'd just ask.

-Slice the sprite in the sprite editor, but I'd have to draw boxes over every single line.

-Research if raycasts can detect a certain colour. (I haven't learnt raycasts yet)

-Learn blender and use the maze image as a guide and plonk cubes on it to make a 3d version of it.

-Recreate the maze in game using just a line sprite.

Is there an easier way?

Thanks in advance.

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
0

Answer by frogsbo · Mar 14, 2014 at 06:41 AM

you have to figure out a collision maths that suits you. you probably mean you want the walls to be solid, you dont want to collide like bounce away at same speed you hit and in different direction, which takes more maths.

to make solid, just check position to see if it is in white or black, or check points aorund position to see if any is in black... if it is in black, change position to be +x and or +y the same so he is still moving forward up or left, but change one of the x or y so that he is not advancing into wall.

Comment
Add comment · Show 2 · 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 frogsbo · Mar 14, 2014 at 06:45 AM 0
Share

to make a 3d version in cubes, you can measure the grid of your maze, and then check every space on grid bitmap if is black or white, and build a grid of cubes, using 7-8 lines of code...

 for(loop x in grid length){
 
 for (loop y in grid height){ 
 
 if space xy readpixel of bitmap is black(bitmap.red is<.5), make a square there)
 
 }
 
 }
avatar image Raithen · Mar 14, 2014 at 08:00 AM 0
Share

Hi Frogsbo, thanks heaps for answering. I'm just wanting to have if my character touches one of the walls then a trigger event happens, I'm not going to be using physics.

To more clearly define my problem is the maze i made is one single huge image that is imported as a single sprite. Thus I can't make use of any of the 2d colliders on it as they won't map out each of the lines of a single sprite but rather the whole outside of the entire maze.

I'll try the readpixel bitmap.red thing! thanks

Thanks again for your help

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

21 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

Related Questions

How do you create complex collision geometry to match 2D sprites? 2 Answers

Player Destroy on Collision? 0 Answers

Generating 2D collisions for maze 0 Answers

How do I check if/where in a sprite another sprite is? 0 Answers

Changing sprites from spritesheet on collision. What am I doing wrong? 1 Answer


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