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 adit1 · Jan 17, 2013 at 12:55 AM · 2dcollisionraycasting

How do I make ray cast to detect land?

I'm trying detect the land before the player in 2d game so that it can alert. Ray should be front and downside so that player can see the land. How can I make the direction this way? Any ideas?

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 Anxo · Jan 17, 2013 at 12:59 AM

Yes, Type Raycast in the Scripting Reference and you will find how to do exactly that. Cast a ray down before an object hits the floor.

Comment
Add comment · Show 5 · 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 adit1 · Jan 17, 2013 at 01:00 AM 0
Share

So for down direction we have to make var fwd = transform.TransformDirection (0,-1,0);? as y -1?

avatar image Anxo · Jan 17, 2013 at 01:04 AM 0
Share

sounds right. did not look into it but yes. Y is your up and down so -1 sounds right.

avatar image Anxo · Jan 17, 2013 at 01:05 AM 0
Share

But that is only if your character's down ever changes. Otherwise you can just not make a fwd var and just always have it pointing in world down.

avatar image adit1 · Jan 17, 2013 at 01:20 AM 0
Share

I'm trying to do forward direction and downwards, taking var fwd = transform.TransformDirection (1,-0.5,0); to get the angle, but it's not working.

avatar image Anxo · Jan 17, 2013 at 02:01 AM 0
Share

oh. Well that all depends on which way you your character is orientated in the world, and within its own transform. What you can do is put an empty game object inside your characters game object. Name it something like downForwardDirection. Rotate the empty game object so that it's Z axis points in the direction you want the ray to fire or what ever. Then say fwd = downForwardDriection.transform.TransformDirection(0.0.1);

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

9 People are following this question.

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

Related Questions

My Raycasts seem to sometimes miss 0 Answers

onGround raycasts return onGround is true while colliding with platform sides 0 Answers

Object following a path and colliding with other objects with physics. 1 Answer

How to use `Physics2D.IgnoreCollision()` to implement a one-way platform? 0 Answers

Moving a player smoothly without breaking collisions? 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