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 Daniel G · Aug 06, 2013 at 11:03 PM · supportmesh manipulation

Understanding Vehicle Damage script Variables?

Hello,

I need help understanding what each of the variables in this script will do, I have tested over and over and seem to get random results.

I bought this script but the seller is NO longer answering me, I need help!

I am an avid game maker, and understand a fair amount of javascript BUT I'm new to mesh manipulation.

CODE:

 #pragma strict
 var maxDamage:float=0.6;
 var maxCollPower:float=50.0;
 var destroyRange:float=0.7;
 var dirManipulator:float=0.95;
 var meshes:MeshFilter[];
 private var sqrDestRange:float;
 
 function Start(){
     sqrDestRange = destroyRange*destroyRange;// sqr of destroy range
 }
     
 function OnCollisionEnter(coll:Collision){
     if(coll.contacts.Length>0){//fix a little bug of physics in Unity
         for(var i:int=0; i<coll.contacts.Length; i++){
             var collPoint : Vector3 = coll.contacts[0].point;//contact point
             var collRelVel : Vector3 = coll.relativeVelocity;
             var collPointToMe:Vector3 = transform.position - collPoint;//convert to me
             var collPower:float = collRelVel.magnitude * Vector3.Dot(coll.contacts[0].normal, collPointToMe.normalized);//power calculate
             OnMeshForce(collPoint, Mathf.Clamp01(collPower/maxCollPower));//go next step
         }
     }
 }
 
 function OnMeshForce(originPosAndForce:Vector4){
     originPosAndForce = Vector3(originPosAndForce.x,originPosAndForce.y,originPosAndForce.z);//recalculate to Vector3
     OnMeshForce(originPosAndForce, originPosAndForce.w);//next
 }
 
 function OnMeshForce(originPos:Vector3, force:float){
     force = Mathf.Clamp01(force);
     for(var j:int=0; j<meshes.Length; j++){
         var verts:Vector3[] = meshes[j].mesh.vertices;//temp verts
         for (var i:int=0; i<verts.Length; i++){
             var scaledVert:Vector3 = Vector3.Scale(verts[i], transform.localScale );                        
             var vertWorldPos:Vector3 = meshes[j].transform.position + (meshes[j].transform.rotation * scaledVert);
             var originToMeDir:Vector3 = vertWorldPos - originPos;
             var flatVertToCenterDir:Vector3 = transform.position - vertWorldPos;
             flatVertToCenterDir.y = 0.0;
             if(originToMeDir.sqrMagnitude < sqrDestRange){
                 var dist:float = Mathf.Clamp01(originToMeDir.sqrMagnitude/sqrDestRange);
                 var moveDelta:float = force * (1.0-dist) * maxDamage;
                 var moveDir:Vector3 = Vector3.Slerp(originToMeDir, flatVertToCenterDir, dirManipulator).normalized * moveDelta;
                 verts[i] += Quaternion.Inverse(transform.rotation)*moveDir;
             }
         }
         meshes[j].mesh.vertices = verts;
         meshes[j].mesh.RecalculateBounds();
     }
 } 



Please do not steal this script, No its not copyrighted, but support the developer if you want to use it. It's a GREAT small little package thats EASY to change and add to! HERE: http://activeden.net/item/4-wheels-car-physic-damage-and-repair-system/4453624

Thank you.

Daniel

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 Daniel G · Aug 06, 2013 at 11:04 PM 0
Share

If this is a violation, I will be happy to remove my Question and ask some one privately. Thanks

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.

Follow this Question

Answers Answers and Comments

14 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

Related Questions

How does this code generate movement using player input? Does it have some in-engine code? 1 Answer

Added torque value, like in rigidbody.velocity.magnitude? 0 Answers

Unexpected symbol 'Flip' and 'else' 1 Answer

Multimesh models / changing meshes between them 1 Answer

Problem with setting vertices positions and smoothing groups. 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