从起点到终点的距离,以更新百分比表示 [英] Distance from start point to end point in percentage in update

查看:101
本文介绍了从起点到终点的距离,以更新百分比表示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

float curpos = player.transform.position.magnitude;
float targetpos=GameObject.Find ("target").transform.position.magnitude;
float percentDist = (curCarpos / targetpos) * 100;

我想做的是计算从当前点一直到终点的百分比,从零开始,一旦到达终点就应该是100.

What I want to do is calculate percentage along the way from current point which is always moving to end point, starting from zero and once it reaches it should be 100.

由于某种原因,它从14%下降到0%,然后从0%-99%开始.

For some reason it is starting from 14% decreasing to 0% and then starting from 0%-99%.

推荐答案

您做的所有事情都是错误的.向量大小在这种情况下是没有用的.您需要这样的东西:

You do it all wrong. Vectors magnitude in this case it is useless. You need something like this:

在进行所有动作之前先打电话给它.

Call this before all movement.

float startDistance = Vector3.Distance(player.transform.position, target.transform.position);

这是运动中的.

float currentDistance = Vector3.Distance(player.transform.position, target.transform.position);

float percentage =(currentDistance / startDistance) * 100f;

这篇关于从起点到终点的距离,以更新百分比表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆