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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Demon pete · Nov 22, 2012 at 10:33 AM · raycastlayeraimcrosshair

Problem with raycast aim, need help ignoring layers/tags and pointing at the end of the ray.

I am making a space type dog fighting game similar to moonbreakers on steam. but i have been having a little trouble geting all the aims correct.

I decided that i am going to make a raycast to cursor position and move a empty object to the hit possition then have my forward guns and missle launcher aim at that, so far it works fine but as long as i am looking at something with a colider.

However, i want it so that if it is not hitting a colider then it just moves the empty game object to say the end of the ray cast. also i was wondering how i would add in anything that would make the ray ignore the "player" Layer or Tag.

here is what i have so far (My knowlege of java is poor, But i am taking the best steps i can to improve),

// Moves the object with this script to the point of the raycast hit

function Update () { // Send a ray through the cursor var ray : Ray = (Camera.main.ScreenPointToRay(Input.mousePosition)); // Do a raycast var hit : RaycastHit; if (Physics.Raycast (ray, hit)) transform.Translate((hit.point - transform.position)); }

Any help is much apreciated. Thank you.

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
0
Best Answer

Answer by AeonIxion · Nov 22, 2012 at 01:01 PM

For the ignore player problem: Rather than ignoring the player, you'll want the player to ignore the raycast. Click on your player object and change the layer to 'ignore raycast'.

As for moving the empty gameobject if not colliding, you'll want an else with a Translate that moves the object to ray.direction*value (where value is any value really).

  else
     {
     transform.Translate(ray.direction*100);
     
     }

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 Demon pete · Nov 23, 2012 at 10:36 AM

Ah thank you, looking at it now i don't know how i didn't figure that one out on my own, but you help has been much appreciated.

as for the ray cast ignoring player i got that one figured out eventually as i can't move it to the ignore raycast layer because i need the ship to interact with other ray cast i have going on. so far it works like a charm so i will put up the finished version or what i have tomorrow.

again thanks.

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

10 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

Related Questions

How make Raycast Aim to Crosshair? 1 Answer

How do I tell what NavMeshLayer a NavMeshAgent is currently on? 0 Answers

Touch and aim with a raycast line 2 Answers

Unable to set collision layer from scrip 0 Answers

Layermask (raycast) wont work... 4 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