首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >滤网化妆品损伤

滤网化妆品损伤
EN

Stack Overflow用户
提问于 2015-05-08 20:10:23
回答 1查看 254关注 0票数 0

目前,试图工作的脚本,允许一个球采取化妆品网眼的损害,因为它通过一个水平。问题是,我一直很难找到移动顶点的合适方程。

这是我现在所拥有的

代码语言:javascript
运行
复制
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;
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-15 17:52:25

引用自:http://answers.unity3d.com/questions/962794/mesh-collision-damage.html#answer-966389

我建议两种选择: 使用随机变形,例如: meshCoordinateslastIndex +=新Vector3(Random.Range(-DeformScale,DeformScale), Random.Range(-DeformScale,DeformScale),Random.Range(-DeformScale,DeformScale); 用逆法向内偏移顶点: meshCoordinateslastIndex -= meshCoordinateslastIndex.normalized * DeformScale;

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30132101

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档