###前提・実現したいこと
すでに配置された4つのRigidBodyにRepulsor.jsというスクリプトを入れて、斥力をかけたい
Rigidbody同士はHingeJointがComponentされており、全てのRigidBodyが均一に広がるようにしたい
###発生している問題・エラーメッセージ
均一に広がらず、中心がずれていってしまう
###該当のソースコード
Javascript
1 2#pragma strict 3static var blastForce = 4; 4static var blastRadius = 10; 5var implode = true; 6 7 8 9function FixedUpdate () { 10 var things : Collider[] = Physics.OverlapSphere(transform.position, blastRadius); 11 for (var i=0; i<things.length; i++){ 12 if (things[i].attachedRigidbody && things[i].attachedRigidbody != GetComponent.<Rigidbody>()){ 13 var offset : Vector3 = (transform.position - things[i].transform.position); 14 if(0<=offset.x && offset.x<0.1){ 15 offset.x = 0.1; 16 }else if(-0.1<offset.x && offset.x<0){ 17 offset.x = -0.1; 18 } 19 20 if(0<=offset.z && offset.z<0.1){ 21 offset.z = 0.1; 22 }else if(-0.1<offset.z && offset.z<0){ 23 offset.z = -0.1; 24 } 25 things[i].attachedRigidbody.AddForce(-blastForce/offset.x, 0, -blastForce/offset.z); 26 } 27 } 28}
###試したこと
ForceやRadiusの大きさを変えたり、Rigidbodyとの距離によってかかる力を変えたりしたが、均一に広がらなかった
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。