C# 网滤器外观损坏
目前正在尝试编写一个脚本,允许球在通过关卡时受到装饰性网格伤害。问题是,我一直很难找到移动顶点的合适方程式 这是我要的,苏斯法C# 网滤器外观损坏,c#,unity3d,collision,mesh,destroy,C#,Unity3d,Collision,Mesh,Destroy,目前正在尝试编写一个脚本,允许球在通过关卡时受到装饰性网格伤害。问题是,我一直很难找到移动顶点的合适方程式 这是我要的,苏斯法 using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; public class MeshDenter : MonoBehaviour { Vector3[] originalMesh; public
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;
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用UnityEngine;
公共类MeshDenter:单一行为{
矢量3[]原始网格;
公众参与因素;
公共层掩码冲突掩码;
私有网过滤器;
void Start(){
meshFilter=GetComponent();
originalMesh=meshFilter.mesh.vertices;
}
无效碰撞中心(碰撞){
Vector3[]网格坐标=原始网格;
//循环通过碰撞点
foreach(碰撞中的接触点。接触点){
//索引到点的最近距离。
int lastIndex=0;
//通过网格坐标循环
对于(int i=0;i
引自:
我建议两种选择:
使用随机变形,如:
meshCoordinates[lastIndex] += new Vector3(Random.Range(-DeformScale,DeformScale),
随机范围(-DeformScale,DeformScale),
随机范围(-DeformScale,DeformScale))
通过反向法线偏移顶点向内凹陷,如:
meshCoordinates[lastIndex] -= meshCoordinates[lastIndex].normalized * DeformScale;
您可以检查
反射调用的参数。游戏本质上是2D还是3D?如果您的运动主要是二维的,则相应的碰撞。相对级别会限制您的输出。此脚本会操纵三维网格。游戏本身就是2D风格的