Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
1
Question by JoySeeker · Jan 02, 2016 at 02:34 AM · rigidbodyhinge jointmotor

[FIXED] Changing the Target Velocity of a Hinge Joint Motor in script

I'm trying to get a Rigidbody to turn itself as it moves around a point by using a hinge joint motor. The only value I need to affect is the Target Velocity. When I initially tried this, I got an error telling me to store hingejoint.motor.targetvelocity as a temporary variable before altering it and reassigning it (getting it and setting it;) however, now that I've done that, I get no errors, but the target velocity remains how it was set before runtime. Here's my code:

 using UnityEngine;
 using System.Collections;
 
 public class MerryGoRound : MonoBehaviour {
 
     public GameObject funnel;
     public float turnSpeed = 1f;
 
     HingeJoint joint;
     JointMotor motor;
 
     void Start () {
         joint = GetComponent<HingeJoint>();
         motor = joint.motor;
     }
     
     void FixedUpdate () {
         Vector3 line1 = funnel.transform.position - transform.position;
         Vector3 line2 = (funnel.transform.position + new Vector3(0f, 10f, 0f)) - transform.position;
         Vector3 perp = Vector3.Cross(line1, line2);
         Vector3 wheelForwardVector = transform.forward;
 
         float tempTargetVelocity = motor.targetVelocity;
         tempTargetVelocity = Vector3.Angle(wheelForwardVector, perp) * turnSpeed;
         motor.targetVelocity = tempTargetVelocity;
     }
 }
 
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 JoySeeker · Jan 02, 2016 at 10:34 PM 0
Share

Here's the code that works:

 using UnityEngine;
 using System.Collections;
 
 public class $$anonymous$$erryGoRound : $$anonymous$$onoBehaviour {
 
     HingeJoint myJoint;
     Joint$$anonymous$$otor myJoint$$anonymous$$otor;
     public float targVel = 2f;
 
     void Start () {
         myJoint = GetComponent<HingeJoint>();
     }
     
     void Update()
     {
         myJoint$$anonymous$$otor = myJoint.motor;
         myJoint$$anonymous$$otor.targetVelocity = targVel;
         myJoint.motor = myJoint$$anonymous$$otor;
     }
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Tronyc · Dec 27, 2017 at 04:02 AM

This didn't work for me. I entered the code exactly as shown in the comment to your post, except I'm using motorSpeed instead of targetVelocity. Does that make a difference? I really need to be able to control the movement of the Joint.

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

Hinge Joint Doesn't Move Unity 2018.4.17f1 0 Answers

Rigidbody going through wall during pinch-to-zoom 0 Answers

Move 2 objects as one 0 Answers

How to move a kinematic rigidbody with touch? 0 Answers

how to modify another objects kinematic state? 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