我想沿着一条线移动一个物体(例如一只小猫)。我不知道如何使用move.object
或transform.translate
等功能...请帮助我。
在这里,我的代码开始:
<!DOCTYPE html>
<html>
<head>
<script>
function dessinerLigne(ax, ay, bx, by) {
if (ay > by) {
bx = ax + bx;
ax = bx - ax;
bx = bx - ax;
by = ay + by;
ay = by - ay;
by = by - ay;
}
var calc = Math.atan((ay - by) / (bx - ax));
calc = (calc * 180) / Math.PI;
var length = Math.sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
document.body.innerHTML += "<div id='ligne' style='height:" + length + "px;width:1px;background-color:black;position:absolute;top:" + (ay) + "px;left:" + (ax) + "px;transform:rotate(" + calc + "deg);-ms-transform:rotate(" + calc + "deg);transform-origin:0% 0%;-moz-transform:rotate(" + calc + "deg);-moz-transform-origin:0% 0%;-webkit-transform:rotate(" + calc + "deg);-webkit-transform-origin:0% 0%;-o-transform:rotate(" + calc + "deg);-o-transform-origin:0% 0%;'></div>"
}
var pointB: (1055, 105);
function Start() {
var pointA = transform.position(585, 890);
while (true) {
yield MoveObject(transform, pointA, pointB, 3.0);
yield MoveObject(transform, pointB, pointA, 3.0);
}
}
function MoveObject(thisTransform: Transform, startPos: Vector3, endPos: Vector3, time: float) {
var i = 0.0;
var rate = 1.0 / time;
while (i < 1.0) {
i += Time.deltaTime * rate;
thisTransform.position = Vector3.Lerp(startPos, endPos, i);
yield;
}
}
</script>
</head>
<body onload="dessinerLigne(1055,105,585,890);">
</body>
<body background="map.jpg"></body>
</html>`enter code here`