簡體   English   中英

AS3將對象移動和旋轉到3D空間中的某個點

[英]AS3 Move and Rotate a object to a point in 3D space

你好,

我試圖將3D階段中的對象(我正在使用away3d框架)移動到空間中的某個點(矢量3d),其工作正常,但我希望該對象將其“正面”轉到該點,因此它將離開它“尋找”並“走向”它。

移動對象的代碼:

Tweener.addTween(
  mainReference.carHolder, 
  { 
    time:.1, 
    x:points[point].x, 
    y:points[point].y, 
    z:points[point].z, 
    transition:"Linear", 
    onComplete:function():void 
    { 
      moveCar(point + 1); 
    } 
  });

我已經嘗試了什么:

var angleX:Number = Vector3D.angleBetween(
  new Vector3D(
    mainReference.carHolder.x, 
    mainReference.carHolder.y, 
    mainReference.carHolder.z), 
  new Vector3D(
    mainReference.carHolder.x, 
    points[point].y, 
    points[point].z)
) * 180 / Math.PI;

var angleY:Number = Vector3D.angleBetween(
  new Vector3D(
    mainReference.carHolder.x, 
    mainReference.carHolder.y, 
    mainReference.carHolder.z), 
  new Vector3D(
    points[point].x, 
    mainReference.carHolder.y, 
    points[point].z)
) * 180 / Math.PI;

var angleZ:Number = Vector3D.angleBetween(
  new Vector3D(
    mainReference.carHolder.x, 
    mainReference.carHolder.y, 
    mainReference.carHolder.z), 
  new Vector3D(
    points[point].x, 
    points[point].y, 
    mainReference.carHolder.z)
) * 180 / Math.PI;

var angle:Number = Vector3D.angleBetween(
  new Vector3D(
    mainReference.carHolder.x, 
    mainReference.carHolder.y, 
    mainReference.carHolder.z), 
  new Vector3D(
    points[point].x, 
    points[point].y, 
    points[point].z)
) / 180 * Math.PI;

mainReference.carHolder.eulers = new Vector3D(
  points[point].x, 
  points[point].y, 
  points[point].z);
mainReference.carHolder.rotateTo(
  points[point].x, 
  points[point].y, 
  points[point].z);

您是否嘗試過lookAt()方法?

從文檔:


看着()
公共函數lookAt(target:Vector3D,upAxis:Vector3D = null):void旋轉3d對象以面向相對於父ObjectContainer3D的局部坐標定義的點。

參量

target Vector3D —定義要查看的點的向量

upAxis:Vector3D(默認= null)—可選矢量,用於定義旋轉發生后3d對象的所需向上方向


這樣可以使您的對象在移動到目標位置時注視目標位置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM