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 NeatCrown · Jan 20, 2015 at 02:46 AM · colliderwheelcolliderrigidbody.velocity

Error CS0120 and CS1612 - Wheelcollider sidewaysFriction and Rigidbody.velocity

I'm currently working on a car project due in 2 days, and having some issues:

The error I'm having is:

"CS1612(XX,25(XX represents line 59-62)): Cannot modify a type return value of 'UnityEngine.WheelCollider.sidewaysFriction'. Consider storing the value in a temporary variable"

Here's my (C#)Code (I Used the '*' to show the error area):

 using UnityEngine;
 using System.Collections;
 
 public class DriveScriptC : MonoBehaviour{
 
     public float motorForce;
     public float SteerAngle;
     public WheelCollider BLWheel;
     public WheelCollider BRWheel;
     public WheelCollider FLWheel;
     public WheelCollider FRWheel;
     public float brakeForce;
 
     
 
     public GameObject fin;
 
     public bool CheckpointA;
 
     public float slip;//slip of the velicle
 
     public float hit;
 
     public WheelFrictionCurve sidewaysFriction;
 
     // Use this for initialization
     void Start () 
     {//what vars are
         slip = 0;
         CheckpointA = false;
         fin = GameObject.FindWithTag ("Finish");
     }
     
     // Update is called once per frame
     void Update () {
         float v = Input.GetAxis ("Vertical") * motorForce;//
         float h = Input.GetAxis ("Horizontal") * SteerAngle;//declaring var 
         //motor power
         BLWheel.motorTorque = v;
         BRWheel.motorTorque = v;
         //steering
         FLWheel.steerAngle = h;
         FRWheel.steerAngle = h;
 
 
         if (Input.GetKey (KeyCode.Space)) {//When SpaceBar is down(held), apply brake
             BLWheel.brakeTorque = brakeForce;
             BRWheel.brakeTorque = brakeForce;
         }
 
         if (Input.GetKeyUp (KeyCode.Space)){//When SpaceBar is up(not held), don't apply brake
             BLWheel.brakeTorque = 0;
             BRWheel.brakeTorque = 0;
         }
 
 
         *slip = 0.001 + 0.022 / (rigidbody.velocity.magnitude + 1);*
         *//velocity-slip curve*
         *FLWheel.sidewaysFriction.stiffness = slip*Time.deltaTime; //         X*
         *FRWheel.sidewaysFriction.stiffness = slip*Time.deltaTime; //       XX*
         *BLWheel.sidewaysFriction.stiffness = slip*Time.deltaTime; //    XXX*
         *BRWheel.sidewaysFriction.stiffness = slip*Time.deltaTime; //XXXX*
 
         WheelHit FLhit;
         WheelHit FRhit;
         WheelHit BLhit;
         WheelHit BRhit;
 
         if(FLWheel.GetGroundHit(out FLhit)){
             if(FLhit.collider.gameObject.tag == "Finish"){
                 if(CheckpointA == true){//if Checkpoint selected
                     print("FINISH!");//Print "Finish"
                 }
             }
         }
         if(FRWheel.GetGroundHit(out FRhit)){
             if(FRhit.collider.gameObject.tag == "Finish"){
                 if(CheckpointA == true){//if Checkpoint selected
                     print("FINISH!");//Print "Finish"
                 }
             }
         }
         if(BLWheel.GetGroundHit(out BLhit)){
             if(BLhit.collider.gameObject.tag == "Finish"){
                 if(CheckpointA == true){//if Checkpoint selected
                     print("FINISH!");//Print "Finish"
                 }
             }
         }
         if(BRWheel.GetGroundHit(out BRhit)){
             if(BRhit.collider.gameObject.tag == "Finish"){
                 if(CheckpointA == true){//if Checkpoint selected
                     print("FINISH!");//Print "Finish"
                 }
             }
         }
     }
 }


I do admit, I am kind of a newbie...

Comment
Add comment · Show 2
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 getyour411 · Jan 20, 2015 at 02:52 AM 0
Share

It should be rigidbody; your numbers like 0.22 should end in f (i.e 0.22f)

avatar image NeatCrown · Jan 20, 2015 at 06:48 PM 0
Share

"CS0120(57,51): An object reference is required to access non-static member 'UnityEngine.WheelCollider.velocity'" was solved. Thanks, getyour411.

Any idea how to solve the other?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by carrollh · Jan 20, 2015 at 07:42 PM

I at first though this was a scope error, but stiffness is public. Maybe it's because you have to use the WheelCollider.GetGroundHit, and then use the friction components in the value returned from it...?

The WheelCollider.GetGroundHit API says "any simulation of different ground materials must be done manually by adjusting forwardFriction and sidewaysFriction based on collider's material returned here."

And the WheelFrictionCurve API demos it as

         var hit : WheelHit;
         var wheel : WheelCollider = GetComponent(WheelCollider);
         if( wheel.GetGroundHit( hit ) ) {
             wheel.forwardFriction.stiffness = hit.collider.material.staticFriction;
             wheel.sidewaysFriction.stiffness = hit.collider.material.staticFriction;
         }


So maybe try implementing a WheelHit instance with a material on it, and then query and use that to set the stiffness. I'm at a loss as to exactly why you can't set it manually like you are though. Looking at the visibility of the things, I would think your original 4 lines of code would at least compile.

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

Stopping gameobject with colliders 1 Answer

How to detect my car is drifting or not ? 1 Answer

Wheel colliders act weird 0 Answers

Best Settings/Config Wheelcollider Tank 0 Answers

Internal collisions 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