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 renaxi · Aug 13, 2014 at 07:19 PM · javascriptphysicsrigidbodyraycastcollider

Trouble with RayCast, rigid body and the colliders tag

Hello, i have been working on a inventory system and so far i haven't been running into much trouble, but now i have run into a problem. I am trying to pick the items up with a RayCast function, so when i press E, the hit.collider.gameObject.tag checks if the item have the tag "LootAble".

Now here is the problem. I have a rigid body component attached to the object, so it falls to the ground. But whenever i turn IsKinematic false, so the object gets affected by gravity, the object is just tagged as "Untagged". When IsKinematic is true, the object doesn't get affected by gravity, but the tag is changed to "LootAble"

 #pragma strict
 
 var RayLength : int = 5;
 
 function Update () 
 {
     if(Input.GetKeyDown(KeyCode.E))
     {
         PickItemUp();
     }
 }
 
 function PickItemUp()
 {
     var hit : RaycastHit;
     var fwd = transform.TransformDirection(Vector3.forward);
     
     if(Physics.Raycast(transform.position, fwd, hit, RayLength))
     {
            Debug.Log(hit.collider.tag);
         if(hit.collider.gameObject.tag == "LootAble")
         {
             Debug.Log("Great! You seem to be able to loot this object, please assign a function");
         }
     }
 }

Is there any way, that i can still make the object get pulled towards the ground (Terrain), while IsKinematic is true, or is any way that i can make RayCast recognize the objects tag, while IsKinematic is false?

Comment
Add comment · Show 1
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 robertbu · Aug 13, 2014 at 07:21 PM 0
Share

I doubt the tag is changing. $$anonymous$$y guess is that your Raycast() is hitting something. Check the 'hit.collider.name' to see. In addition, while the game is running, select your falling object in the hierarchy and look at the tag.

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

When and when not to use kinematic rigidbody? 2 Answers

Slant Physics Raycast Implementation 0 Answers

driving game power ups 1 Answer

Applying proper drag and center of mass for a vehicle 1 Answer

Drag Rigid Bodies First Person Controller.js 0 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