Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Korudo · Dec 22, 2015 at 12:55 PM · unity 5collision detectionraycastingtutorial

Unity C# Casual Jewel Mining Game - Jewel Unaffected by Claw

Hello,

I am following the Unity Live Training tutorial (https://www.youtube.com/watch?v=QvZ6Q3TmoRI) and I can't get the Claw to grab the Jewel game objects. The Claw works on the Rock game object just fine. The raycaster will reach the jewel, but retract as if blocked (like the barrier below). My goal is to have the claw grab the game object, becoming the parent of that game object, and destroying it once it reaches the Origin point.

I tagged the jewels "Jewel" and wrote the following scripts:

For the shooting and raycasting:

  using UnityEngine;
     using System.Collections;
     
     public class Gun : MonoBehaviour {
     
         public GameObject claw;
         public bool isShooting;
         public Animator minerAnimator;
         public Claw clawScript;
     
     
     
         void Update () 
         {
             if (Input.GetButtonDown("Submit") && !isShooting) 
             {
                 LaunchClaw ();
             }
         }
     
     
         void LaunchClaw()
         {
             isShooting = true;
             minerAnimator.speed = 0;
             RaycastHit hit;
             Vector3 down = transform.TransformDirection (Vector3.down);
     
             if (Physics.Raycast (transform.position, down, out hit, 100))
             {
                 claw.SetActive (true);
                 clawScript.ClawTarget (hit.point);
             }
         }
     
         public void CollectedObject()
         {
             isShooting = false;
             minerAnimator.speed = 1;
         }
     }

and this for the Claw game object to interact with the Jewel game objects:

 using UnityEngine;
     using System.Collections;
     
     public class Claw : MonoBehaviour {
     
         public Transform origin;
         public float speed = 4f;
         public Gun gun;
         public ScoreManager scoreManager;
     
         private Vector3 target;
         private int jewelValue = 100;
         private GameObject childObject;
         private LineRenderer lineRenderer;
         private bool hitJewel;
         private bool retracting;
     
         void Awake()
         {
             lineRenderer = GetComponent<LineRenderer> ();
         }
     
         void Update()
         {
             float step = speed * Time.deltaTime;
             transform.position = Vector3.MoveTowards (transform.position, target, step); 
             lineRenderer.SetPosition (0, origin.position);
             lineRenderer.SetPosition (1, transform.position);
             if (transform.position == origin.position && retracting) 
             {
                 gun.CollectedObject ();
                 if (hitJewel)
                 {
                     scoreManager.AddPoints (jewelValue);
                     hitJewel = false;
                 }
     
                 Destroy (childObject);
                 gameObject.SetActive (false);
             }
         }
     
         public void ClawTarget(Vector3 pos)
         {
             target = pos;
         }
     
         void OnTriggerEnter(Collider other)
         {
             retracting = true;
             target = origin.position;
     
             if (other.gameObject.CompareTag ("Jewel")) 
             {
                 hitJewel = true;
                 childObject = other.gameObject;
                 other.transform.SetParent (this.transform);
             }
     
             else if (other.gameObject.CompareTag("Rock"))
                 {
                     childObject = other.gameObject; 
                     other.transform.SetParent (this.transform); 
                 }
         }
     }

Any help would be greatly appreciated. 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Korudo · Dec 23, 2015 at 12:06 PM

If anyone reads this in the future, I figured it out. I had to tag the Mesh for the Jewels as "Jewel", not just the Jewel game objects. :)

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

41 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UFO Tutorial, after pickup vid, my player ignores the wall collisions 0 Answers

Raycast is not hitting collider 2 Answers

Is there a way for creating composite raycast collisions ? 0 Answers

Line renderer's edge collider sometimes not detecting collisions with object 0 Answers

TANKS! unity tutorial shooting not working? 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