- Home /
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?
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.
Your answer
Follow this Question
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