开发者

Magnitude Position

There is an cube wich scales with the distance.magnitude between the player and the enemy. I want to set this Scaling Cube in the middle between the hero and the enemy. So is it possible to use the mangitude between two objects as a position.

This is my script:

var hero : Transform;
var enemy : Transform;
var magDistance = 0.0;
var setPosition = 0.0;

function Update () {
    var heDistance : Vector3 = (hero.position - enemy.position)/2;
    magDistance = heDistance.magnitude;
    setPosition = heDistance.magnitude/2;
    transform.localScale = Vector3(1,1,magDistance);
}

Im using the heDistance.magnitude/2 to get the middle of the distance. Help is much appreciated开发者_如何学Go. Thanks in advance! :)


I hate to even ask, but can't you just do:

x = (hero.position.x+enemy.position.x)/2
y = (hero.position.y+enemy.position.y)/2
z = (hero.position.z+enemy.position.z)/2

to get the point between the two points? Or, if vector addition works in the usual way:

var cube_pos: Vector3 = (hero.position + enemy.position)/2;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜