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 $$anonymous$$ · Jul 18, 2013 at 09:11 PM · transform.positionloopraycasthitsidescroller

RayCastHit

Hello,

I have 1 problem with raycast.

Code:

 #pragma strict
 
 var dot : Transform;
 var defDotPos : Vector3 = Vector3(0, 1000, 0);
 
 function Update()
 {
     var ray = transform.TransformDirection(Vector3.forward);
     var hit : RaycastHit;
 
     if (Physics.Raycast(transform.position , ray , hit, 150))
     {
         dot.position = hit.point;
     }
     else 
     {
         dot.position = defDotPos;
     }
 }

This script is supposed to show a point(sphere) on the object which is in front of the character, but actually it loops sphere between character and that object. here is picture so you can see http://prntscr.com/1g70d7

Its sidescroller im talking about.

Comment
Add comment · Show 2
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 Benproductions1 · Jul 18, 2013 at 11:02 PM 0
Share

There is nothing wrong with that code. It's probably something else thats setting the position.

avatar image robertbu · Jul 18, 2013 at 11:23 PM 0
Share

It is possible you are hitting a collider you do not expect. Put this on line 12:

 Debug.Log(hit.name+","+hit.tag);

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by RyanZimmerman87 · Jul 18, 2013 at 11:46 PM

Really hard to tell what exactly you're trying to do the code is a bit vague. But my best guess is you have some kind of collider intercepting your ray cast before it's expected collision. Most likely the character object if the ray is being cast from inside the character.

Set a layer for your character and ignore that layer in the raycast.

Comment
Add comment · 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
0

Answer by $$anonymous$$ · Jul 19, 2013 at 02:32 PM

this dude is badass: (fix for problem)

http://prntscr.com/1gbjr7

Comment
Add comment · 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

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

16 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

Related Questions

list.contains isn`t working 1 Answer

My grid is getting created on the wonk 1 Answer

Hazards not Working Properly 1 Answer

Setting the position of an object which checked the position under with raycast 0 Answers

Animations - Cycle Offset 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