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 DanjelRicci · Sep 10, 2010 at 09:45 AM · movementobjectdetectionfloor

How to detect if there is a floor in front of a character?

I have some simple jelly characters moving on a defined game area, like a game board with squares. Jelly steps are fixed to snap on the grid one square at a time, and they turn 90 at time, so I'm not using free movement or physics collisions.

Obviusly the floor is limited, and I need the character to move only if there is the floor in front of it.

I already have a collider attached to every jelly, but it's used to detect other jellys when they overlap in the same position. If I attach another collider in front of a jelly, all collisions with other players are messed up.

So, how can I detect if there is a floor in front of the jelly?

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

2 Replies

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

Answer by AliAzin · Sep 10, 2010 at 10:09 AM

You can do raycast for such things, but for performance reasons you shouldn't do it every frame.see docs on Raycast.

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 DanjelRicci · Sep 10, 2010 at 04:09 PM 0
Share

Very good, I think this method could work efficiently. Thanks man! :)

avatar image DanjelRicci · Sep 16, 2010 at 08:31 PM 0
Share

This mehtod worked like a charm, thanks! :D

avatar image
1

Answer by Bampf · Sep 10, 2010 at 02:32 PM

If the game layout is being arranged in the Unity scene editor, then AliAzin's solution of raycasting is probably the best method. It also handles with moving floors, obstacles, and irregularly shaped floors. In fact, you can also use it to detect other jellies before actually going and bumping into them.

But I just thought I'd mention an alternative that sometimes makes sense. You could instead keep a map in memory of where the squares are. This works for levels generated from a file of some kind, or from some kind of formula, rather than levels arranged in the Unity scene editor, because that gives you the map. (If the level is built in the scene editor it is still possible to build a map at runtime, e.g. by casting an NxN array of rays into the scene.)

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 DanjelRicci · Sep 10, 2010 at 04:17 PM 0
Share

Thanks Bampf, your method looks less CPU expensive but actually I don't know well how to create arrays and this kinds of data structures... :) Luckyly I need to check with the Raycast every precise time step and not every frame, so it will do. ;)

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

No one has followed this question yet.

Related Questions

Touch Detection on Object in javascript 0 Answers

,how to check if nothing is touching an object 0 Answers

How do i make a mouse look script? 0 Answers

How do I go about moving an object side to side using the mouse. 2 Answers

Mirroring Object Movement with Mouse Position 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