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 scarletsnake · Oct 04, 2012 at 12:43 AM · c#raycastlayerignore

Modifying the HeadLook Controller in C#

Hey guys.

I've modified the headlook controller itself in C#. Every single code that's being used in my project is written with JS, except for the HeadLook Controller. I can't do the simplest thing; avoiding the Player tag.

 using UnityEngine;
 using System.Collections;
 
 public class CursorHit : MonoBehaviour {
     
     public HeadLookController headLook;
 //    public Transform Player;
     private float offset = 3.5f;
     //public LayerMask mask = 9;//1 << 8;
 
     public LayerMask mask = 6;
     // Update is called once per frame
     void LateUpdate () {
 //
 
     //        int AimRaycast = 8; 
 //int AimRaycastMask = 1 << AimRaycast; 
         
 
         
         
     if (Time.timeScale == 1.0) {    
         if (Input.GetKey(KeyCode.UpArrow))
             offset += Time.deltaTime;
         if (Input.GetKey(KeyCode.DownArrow))
             offset -= Time.deltaTime;
             offset = Input.GetAxis("Mouse Y");
 
 
         
         Ray cursorRay = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
         if (Physics.Raycast(cursorRay, out hit)) {
         
             transform.position = hit.point + offset * Vector3.up;
                     Screen.lockCursor = true;
             //     Physics.IgnoreCollision(Player.collider, collider);
             
         //    print(LayerMask.LayerToName(8));
             
             
         }
         
     
         headLook.target = transform.position;
     }
 }
 }

I can do this just fine in JS, but everything is done a little differently in C#. I want the raycast done here to avoid/ignore any object with the "Player" tag. Can anyone help me? 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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by kmeboe · Oct 04, 2012 at 01:18 AM

I don't have a ton of experience with colliders, so there may be a better/more efficient way to do this. But this should work:

                     if (hit.collider.gameObject.tag != "Player")
                     {
                         // Good to go!
                     }
Comment
Add comment · Show 3 · 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 scarletsnake · Oct 04, 2012 at 09:03 PM 0
Share

Yes, that's exactly what I was looking for, but for some reason this locks the headlook sphere when raycast returns "Player", and wont unlock when it returns any other tag...

avatar image kmeboe · Oct 04, 2012 at 09:24 PM 0
Share

Glad I could answer the question.

Now for your next problem. What is the "headlook sphere"? Are you locking it with a line of code? $$anonymous$$aybe post the relevant code for us to exa$$anonymous$$e.

Edit: sounds like you worked it out.

avatar image scarletsnake · Oct 05, 2012 at 08:06 PM 0
Share

This: http://unity3d.com/support/resources/unity-extensions/head-look-controller

It's pretty cool, and you can gain similar results with what R* has done with $$anonymous$$ax Payne 3, when slightly modified.

avatar image
0

Answer by scarletsnake · Oct 04, 2012 at 09:23 PM

Solved it. Using bits and pieces from here; http://fearedfuture.blogspot.com/2009/08/unity-ray-casting-c-code.html The tag option did work, if the gameObject's tag never came up as Player. I'm sure it'll be useful in the future as well. Thanks for your time.

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 to create User layer that acts like the "Ignore Raycast" layer? 1 Answer

ignore raycast layers problem 1 Answer

Multiple Cars not working 1 Answer

Raycast that ignores object with certain tags? 2 Answers

Distribute terrain in zones 3 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