• 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by isometricLove · Oct 16, 2014 at 06:47 PM · suspension

Coding my sunspension Need HELP PLS

I am trying to make sunspension for box applaying force back if box to close to ground but it dosent work can anyone help, you can test this on box just add script and just // tmA and text rendering stuff or add 4 childs whit text render PTA PTB PTC PTD

using UnityEngine; using System.Collections;

 public class ReycastingSuspension : MonoBehaviour {
 //The distance of ray
 public float RaycastDistance;
 //Variable to play whit in unity editor
 public float SunspensionPower;
    
 // Use this for initialization
 void Start () {
 }
  
 // Update is called once per frame
 void Update ()
 {
  
     //Difines botom corners so thet can later be used for raycasting
     Vector3 pointA = transform.TransformPoint (new Vector3 (0.5f, -0.5f, 0.5f));
     Vector3 pointB = transform.TransformPoint (new Vector3 (0.5f, -0.5f, -0.5f));
     Vector3 pointC = transform.TransformPoint (new Vector3 (-0.5f, -0.5f, 0.5f));
     Vector3 pointD = transform.TransformPoint (new Vector3 (-0.5f, -0.5f, -0.5f));
     TextMesh tmA = (TextMesh)GameObject.Find("PTA").GetComponent<TextMesh>();
     TextMesh tmB = (TextMesh)GameObject.Find("PTB").GetComponent<TextMesh>();
     TextMesh tmC = (TextMesh)GameObject.Find("PTC").GetComponent<TextMesh>();
     TextMesh tmD = (TextMesh)GameObject.Find("PTD").GetComponent<TextMesh>();
                
                 //defines HitColector and executes ray for PointA
                 RaycastHit hitColectorPointA;
                 if (Physics.Raycast (pointA, -transform.up, out hitColectorPointA, RaycastDistance)) {
  
                         //CRatio shoud be formula for how much ray is compresed
                         float CRatioA =hitColectorPointA.distance / RaycastDistance;
  
                         //Add UP force at point to lift thet side if its lower by any other force
                         rigidbody.AddForceAtPosition (Vector3.up * CRatioA * SunspensionPower, pointA, ForceMode.Force);
  
                         // GreenRay if hiting somthing      
                         Debug.DrawRay (pointA, -transform.up * RaycastDistance, Color.green);
                         //Debug.Log (hitColectorPointA.distance);
                         var hitdisA = hitColectorPointA.distance;
                         string RounderA = string.Format("{0:0.##}", hitdisA);
                         tmA.text  = RounderA;
                        
                 } else
                 {
                         //Red Ray if not hiting anything
                         Debug.DrawRay (pointA, -transform.up * RaycastDistance, Color.red);
                 }  
        
        
                 //defines HitColector and executes ray for PointB
                 RaycastHit hitColectorPointB;
                 if (Physics.Raycast (pointB, -transform.up, out hitColectorPointB, RaycastDistance)) {
  
                         //CRatio shoud be formula for how much ray is compresed
                         float CRatioB =hitColectorPointB.distance / RaycastDistance;
  
                         //Add UP force at point to lift thet side if its lower by any other force
                         rigidbody.AddForceAtPosition (Vector3.up * CRatioB * SunspensionPower, pointB, ForceMode.Force);
  
                         // GreenRay if hiting somthing      
                         Debug.DrawRay (pointB, -transform.up * RaycastDistance, Color.green);
                         //Debug.Log (hitColectorPointB.distance);
                         var hitdisB = hitColectorPointA.distance;
                         string RounderB = string.Format("{0:0.##}", hitdisB);
                         tmB.text  = RounderB;
                 } else
                 {
                         //Red Ray if not hiting anything
                         Debug.DrawRay (pointB, -transform.up * RaycastDistance, Color.red);
            
                 }
        
  
  
                 //defines HitColector and executes ray for PointC
                 RaycastHit hitColectorPointC;
                 if (Physics.Raycast (pointC, -transform.up, out hitColectorPointC, RaycastDistance)) {  
  
                         //CRatio shoud be formula for how much ray is compresed
                         float CRatioC = hitColectorPointC.distance / RaycastDistance;
  
                         //Add UP force at point to lift thet side if its lower by any other force
                         rigidbody.AddForceAtPosition (Vector3.up * CRatioC * SunspensionPower, pointC, ForceMode.Force);
  
                         // GreenRay if hiting somthing      
                         Debug.DrawRay (pointC, -transform.up * RaycastDistance, Color.green);
                         //Debug.Log (hitColectorPointC.distance);
                         var hitdisC = hitColectorPointC.distance;
                         string RounderC = string.Format("{0:0.##}", hitdisC);
                         tmC.text  = RounderC;
                 } else
                 {
                         //Red Ray if not hiting anything
                         Debug.DrawRay (pointC, -transform.up * RaycastDistance, Color.red);
                 }
        
  
  
                 //defines HitColector and executes ray for PointD
                 RaycastHit hitColectorPointD;
                 if (Physics.Raycast (pointD, -transform.up, out hitColectorPointD, RaycastDistance)) {  
  
                         //CRatio shoud be formula for how much ray is compresed
                         float CRatioD = (hitColectorPointD.distance / RaycastDistance);
                        
                         //Add UP force at point to lift thet side if its lower by any other force
                         rigidbody.AddForceAtPosition (Vector3.up * CRatioD * SunspensionPower, pointD, ForceMode.Force);
  
                         // GreenRay if hiting somthing      
                         Debug.DrawRay (pointD, -transform.up * RaycastDistance, Color.green);
                         //Debug.Log (hitColectorPointD.distance);
                         var hitdisD = hitColectorPointD.distance;
                         string RounderD = string.Format("{0:0.##}", hitdisD);
                         tmD.text  = RounderD;
                 } else
                 {
                         //Red Ray if not hiting anything
                         Debug.DrawRay (pointD, -transform.up * RaycastDistance, Color.red);
                 }  
             }
         }
  
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 isometricLove · Oct 16, 2014 at 06:53 PM 0
Share

i am trying to achive http://www.youtube.com/watch?v=LG1CtlFRmpU watch from 2:02

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

28 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

Related Questions

Mapping movement to a WheelCollider suspension? 2 Answers

Can't get a raycast suspension system to work properly. 0 Answers

How to create car suspension system? 1 Answer

Tank suspension 1 Answer

Can i use wheel colliders with a character controller? 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