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 dallingtonp · Nov 25, 2014 at 10:48 PM · notworking

Script working on some objects but not others

Hey,

So I have a headscratcher, I have a ragdoll with configurable joints, each with this script attached.

 using UnityEngine;
 using System.Collections;
 
 public class ConfigurableJointProperties : MonoBehaviour 
 {
     public float strength = 10000f;
 
     // Use this for initialization
     void Start () 
     {
     
     }
     
     // Update is called once per frame
     void Update () 
     {
         ConfigurableJoint configurablejoint = gameObject.GetComponent<ConfigurableJoint>();
         JointDrive angularYZDrive = new JointDrive();
         angularYZDrive.mode = JointDriveMode.Position;
         angularYZDrive.positionSpring = strength;
         angularYZDrive.maximumForce = strength;
         configurablejoint.angularYZDrive = angularYZDrive;
         
         JointDrive angularXDrive = new JointDrive();
         angularXDrive.mode = JointDriveMode.Position;
         angularXDrive.positionSpring = strength;
         angularXDrive.maximumForce = strength;
         configurablejoint.angularXDrive = angularXDrive;
         
         JointDrive xDrive = new JointDrive();
         xDrive.mode = JointDriveMode.None;
         xDrive.positionSpring = 0f;
         configurablejoint.xDrive = xDrive;
         
         JointDrive yDrive = new JointDrive();
         yDrive.mode = JointDriveMode.None;
         yDrive.positionSpring = 0f;
         configurablejoint.yDrive = yDrive;
         
         JointDrive zDrive = new JointDrive();
         zDrive.mode = JointDriveMode.None;
         zDrive.positionSpring = 0f;
         configurablejoint.zDrive = zDrive;
     }
 }

This works fine and dandy, thing is its kind of a pain going through all the children and changing this when it needs changing so I created a master script which takes all these scripts and groups them together based on their location, seen here.

 using UnityEngine;
 using System.Collections;
 
 public class RagdollMasterControlScript : MonoBehaviour 
 {
     public GameObject root;
     public GameObject head;
     public GameObject neck;
     public GameObject lowerSpine;
     public GameObject upperSpine;
     public GameObject pelvis;
     public GameObject rightUpperArm;
     public GameObject rightForearm;
     public GameObject rightHand;
     public GameObject leftUpperArm;
     public GameObject leftForearm;
     public GameObject leftHand;
     public GameObject rightThigh;
     public GameObject rightCalf;
     public GameObject rightFoot;
     public GameObject leftThigh;
     public GameObject leftCalf;
     public GameObject leftFoot;
     public float rootPositionSpring = 10000f;
     public float headPositionSpring = 10000f;
     public float torsoPositionSpring = 10000f;
     public float leftArmPositionSpring = 10000f;
     public float rightArmPositionSpring = 10000f;
     public float leftLegPositionSpring = 10000f;
     public float rightLegPositionSpring = 10000f;
 
     void Start () 
     {
 
     }
     
     // Update is called once per frame
     void FixedUpdate () 
     {
 
         head.GetComponent<ConfigurableJointProperties> ().strength = headPositionSpring;
         neck.GetComponent<ConfigurableJointProperties> ().strength = headPositionSpring;
 
         lowerSpine.GetComponent<ConfigurableJointProperties>().strength=torsoPositionSpring;
         upperSpine.GetComponent<ConfigurableJointProperties>().strength=torsoPositionSpring;
 
         pelvis.GetComponent<ConfigurableJointProperties>().strength=rootPositionSpring;
         root.GetComponent<ConfigurableJointProperties>().strength=rootPositionSpring;
 
         rightUpperArm.GetComponent<ConfigurableJointProperties>().strength=rightArmPositionSpring;
         rightForearm.GetComponent<ConfigurableJointProperties>().strength=rightArmPositionSpring;
         rightHand.GetComponent<ConfigurableJointProperties>().strength=rightArmPositionSpring;
 
         leftUpperArm.GetComponent<ConfigurableJointProperties>().strength=rightArmPositionSpring;
         leftForearm.GetComponent<ConfigurableJointProperties>().strength=rightArmPositionSpring;
         leftHand.GetComponent<ConfigurableJointProperties>().strength=rightArmPositionSpring;
 
         rightThigh.GetComponent<ConfigurableJointProperties>().strength=rightLegPositionSpring;
         rightCalf.GetComponent<ConfigurableJointProperties>().strength=rightLegPositionSpring;
         rightFoot.GetComponent<ConfigurableJointProperties>().strength=rightLegPositionSpring;
 
         leftThigh.GetComponent<ConfigurableJointProperties>().strength=leftLegPositionSpring;
         leftCalf.GetComponent<ConfigurableJointProperties>().strength=leftLegPositionSpring;
         leftFoot.GetComponent<ConfigurableJointProperties>().strength=leftLegPositionSpring;
     }
 
 }

I just pop that script onto the root, assign the right objects to their corresponding slots and then I should be able to change the strength variable by group. This works. Kind of. The root/head/torsoSpringPosition variables all work as they should, however the limbs simply aren't responding. I figure it has something to do with the actual limbs because if I stick that script on a cube and assign that cube to the rightForearm slot, the script on the cube responds, but when the right forearm is assigned, nothing. The only difference between the limbs and the rest of the body is they use capsule colliders while the rest use box and spheres, and changing that didn't seem to change anything either. Thoughts?

Comment
Add comment · Show 3
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 tanoshimi · Nov 25, 2014 at 11:06 PM 0
Share

Do you really need to reset the strength in every FixedUpdate step? Why/where does it ever change?

avatar image JNaski · Nov 26, 2014 at 12:14 AM 0
Share

I haven't done ragdoll scripts but I did have a similar problem that my script didn't respond to some objects when it did to others. I found out that when I had duplicated some objects so the tag changing didn't help and they didn't work. Can you have this problem? Or can the na$$anonymous$$g of the object be the problem? if you have same names on different objects.

avatar image dallingtonp · Nov 26, 2014 at 02:06 AM 0
Share

FixedUpdate was just me trying different stuff, had the same problem in Update. I'll look into duplicates, but the entire ragdoll is copy/pasted from the master, so if being a duplicate or having the same name could cause a problem, you'd think none of the ragdoll parts would respond but it's just the arms and legs. I have been doing alot of experimenting so maybe something got wonky in the process, I could just try setting it up from scratch, although I was hoping it was just a $$anonymous$$or oversight on my part.

EDIT: Started from scratch, just took my imported model, used the ragdoll wizard, put the scripts on, and it is still not working on the arms and legs. If you look away from the other stuff, I am basically just telling one script to set a variable on another script, I can not for the life of me figure out what is up with these limbs.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by dallingtonp · Nov 26, 2014 at 03:13 AM

Well problem solved, turns out all the bodypart slots in the control script need to be filled and all those parts need to have the configurablejointproperties script attached, otherwise it throws me a null reference error and everything gets wonky. I hope we all learned a lesson today, null reference errors are scary, scary things.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Following Script Not Working Properly 0 Answers

GuiButton Going To Next Level 0 Answers

Script not working 0 Answers

Menu script not showing up like normal 1 Answer

Jump Script, no luck getting it to work.. 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