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 latsushi · Jul 27, 2014 at 09:52 AM · c#jointhingelimits

Hinge Joint Limits in C sharp

I'm making a pinball demo. I get an error that says error CS1612: Cannot modify a value type return value of `UnityEngine.HingeJoint.limits'. Consider storing the value in a temporary variable. My errors are the lines that say hingeJoint.limits.min & hingeJoint.limits.max. I would be grateful for any help. Thank you for your time and have a nice day.

using UnityEngine; using System.Collections;

public class Flippers : MonoBehaviour {

 float startPosition = 0f;
 float buttonPosition = 45f;
 float flipperStrength = 10000f;
 float flipperTorque = 25f;
 string flipperName = "LeftFlipper";
 
 void Awake () {
     hingeJoint.useSpring = true;
 
 }
 
 // Update is called once per frame
 void Update () {
     JointSpring spring = new JointSpring();

     spring.spring = flipperStrength;
     spring.damper = flipperTorque;

     if (Input.GetButton(flipperName))
         spring.targetPosition = buttonPosition;

     else
         spring.targetPosition = startPosition;

     JointSpring s = new JointSpring();

     hingeJoint.spring = spring;
     hingeJoint.useLimits = true;
     hingeJoint.limits.min = startPosition; // Here's my error
     hingeJoint.limits.max = buttonPosition; // Here's my error
 
 }

}

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
1
Best Answer

Answer by Owen-Reynolds · Jul 27, 2014 at 05:02 PM

It's the same error as when you try to say transform.position.x=6;. You can only assign an entire limits variable. Ex from memory:

 JointLimits jj = hingeJoint.limits;
 jj.min= 3; jj.max=4;
 hingeJoint.limits = jj;

The only reason for the equals in the first line is to keep the bounce variables that you already had.

There's nothing especially virtuous about doing it this way. It's more of getting around a design flaw in java/C#. If everything was just fields, you could always say dog..fur.color.r=1. But whenever something is turned into a Property, you aren't allowed to "reach through" and assign to parts. So you have to copy to a temp, change it, then copy the whole thing back.

Comment
Add comment · Show 1 · 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
avatar image latsushi · Jul 28, 2014 at 05:31 AM 0
Share

Thank you sir.

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

24 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

Related Questions

Hinge joint limits not working. 2 Answers

Hinge Joints, distance to connected body 1 Answer

Disable weight "inheritance" when using HingeJoint2D? 1 Answer

Why are my hinge joints inaccurate? 1 Answer

joint angles after Application.LoadLevel() 1 Answer


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