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 abuklea · Dec 16, 2014 at 10:19 AM · c#collidercoroutinebone

Problem with collider transform inside coroutine, with collider attached to a bone

Hi folks. I am trying to implement a slider control that can be interacted with using a virtual finger (attached to a hand controlled by a razer hydra).

I've simplified here for illustration but basically I want to select a slider/button (sphere) with a finger tip and draw a line between the finger tip and the slider control. I then want to update the line as the hand moves around so it always connects the fingertip and the control.

If I do this in a coroutine CheckControl(), the line is drawn from the slider to an OFFSET position where the fingertip WAS when the scene first starts (i.e. when in T-pose).. if I move the entire humanoid, the line updates but always connects off to the side instead of where the fingertip collider actually is when I move the hands around (as though the collider is parented to the humanoid root bone instead of the finger tip bone). I can see the collider in the correct position on the fingertip in the scene view, but the line does not connect to it.

Can anyone shed any light on what I might be doing wrong?

Thanks


Simplified setup:

  • Rigged humanoid model with IK rig for the arms, which are controlled using hydra controllers

  • Empty object attached to an index finger, with a box collider and a rigidbody (no gravity)

  • A sphere (slider control) that I want to trigger. With a sphere collider and trigger=true

  • Script below attached to the sphere control (trigger)

  • When OnTriggerEnter called, I get a reference to the collider (finger tip) that triggered the sphere and use that in the coroutine (or update) to draw a line between sphere and finger tip

Code:

 using UnityEngine;
 using System.Collections;
 
 public class SliderTest : MonoBehaviour
 {
     protected LineRenderer m_LineRenderer = null;
     protected Collider m_Collider = null;
     protected bool m_Active = false;
 
     void Start()
     {
         // create connection line
         m_LineRenderer = gameObject.AddComponent<LineRenderer>();
         m_LineRenderer.material = new Material(Shader.Find("Particles/Additive"));
         m_LineRenderer.SetColors(Color.blue, Color.green);
         m_LineRenderer.SetWidth(0.01f, 0.01f);
         m_LineRenderer.SetVertexCount(0);
     }

     protected IEnumerator CheckControl()
     {
         while (m_Active)
         {
            Debug.Log("m_Collider.transform.position " + m_Collider.transform.position);
 
            // draw connection line
            m_LineRenderer.SetVertexCount(2);
            m_LineRenderer.SetPosition(0, m_Collider.transform.position);
            m_LineRenderer.SetPosition(1, transform.position);
 
            yield return null;
         }
 
         m_Active = false;
     }
 
     void OnTriggerEnter(Collider obj)
     {
         Debug.Log("Triggered By: " + obj.tag);
 
         if (!m_Active)
         {
             m_Collider = obj;
             m_Active = true;
 
             StartCoroutine(CheckControl());
         }
     }
 }
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
Best Answer

Answer by abuklea · Dec 17, 2014 at 11:48 AM

After sitting on this problem for days I finally worked out the solution.

I needed to call:

 yield return new WaitForFixedUpdate();

instead of:

 yield return null;

...inside the coroutine. I'm not sure if the behaviour has changed from Unity version 4.4, as it was working previously without the call to WaitForFixedUpdate()

Hope this helps someone!

thanks, Allan

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

2 People are following this question.

avatar image avatar image

Related Questions

OnTrigger Stay/Exit - Stay Overriding Exit 2 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Limiting the execution time of a lua script? 0 Answers

Can't get while loop to execute more than once in a coroutine before yielding [Solved] 2 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