0
目前正試圖在一個腳本上工作,該腳本允許一個球在穿過關卡時承受美容網格傷害。問題是,我一直無法找到移動頂點的合適方程。網格過濾器化妝品傷害
繼承人我所thusfar
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
public class MeshDenter : MonoBehaviour {
Vector3[] originalMesh;
public float dentFactor;
public LayerMask collisionMask;
private MeshFilter meshFilter;
void Start() {
meshFilter = GetComponent<MeshFilter>();
originalMesh = meshFilter.mesh.vertices;
}
void OnCollisionEnter(Collision collision) {
Vector3[] meshCoordinates = originalMesh;
// Loop through collision points
foreach (ContactPoint point in collision.contacts) {
// Index with the closest distance to point.
int lastIndex = 0;
// Loop through mesh coordinates
for (int i = 0; i < meshCoordinates.Length; i++) {
// Check to see if there is a closer index
if (Vector3.Distance(point.point, meshCoordinates[i])
< Vector3.Distance(point.point, meshCoordinates[lastIndex])) {
// Set the new index
lastIndex = i;
}
}
// Move the vertex
meshCoordinates[lastIndex] += /*Insert Rest Of Equation Here*/;
}
meshFilter.mesh.vertices = meshCoordinates;
}
void Reset() {
meshFilter.mesh.vertices = originalMesh;
}
}
您可能要檢查的參數給'Reflect'電話。 2D遊戲還是3D遊戲?如果你的運動主要是2D,相應的'collision.relativeVelocity'會傾向於限制你的輸出。 – rutter
該腳本處理3D網格。遊戲本身是2D-ish http://gyazo.com/96f472dc6bfcbc8893290ccf6b4c16e6 –