Problem with lookAt function for Object3D in Away3D 4

Software: Away3D 4.x

luddet, Newbie
Posted: 24 October 2011 08:27 AM   Total Posts: 4

I have a problem with lookAt not functioning properly since I updated to the release version of Flash11 and Away3D 4. Everything worked fine during the incubator build, and also during the Flash 11 beta build.

This is the case:
I have a mesh in an Object3d which is the player that is on a coordinate, lets say 0,0,0 that another mesh in an object3d (an opponent) should look at and follow.

The opponent object is in the same space as the player object and I have made sure that the opponent is getting the correct coordinates (0,0,0) from the player to look at.

The opponent is however looking at an completely different direction than the player is at. The opponent continues to look at that direction even if the coordinates are updated by moving the player. However, when the player is circling round the opponent, the opponent at some angle is turning to follow the player, but when the player reaches a certain angle position the opponents turns back to look at its initial distant point.

var opponentMesh:PrimitiveBase = ((opponent.skin as Away3D4Mesh).mesh as Cube).position;
 
opponentMesh.lookAt((player.skin.mesh as Cube).position); 

What is wrong?
To me it seems to be the Object3D.lookAt function not calculating the looking objects rotation correctly.
I have not changed anything in this behavior, that worked fine before I updated to the release flash player and the newer away version.

Thanks for your help, it is really appreciated!
/Ludwig

   

Avatar
Jeff, Newbie
Posted: 26 October 2011 12:09 AM   Total Posts: 30   [ # 1 ]

Hi,

I had the same issue than you, as a temporary fix copy & paste the lookAt code from previous release. In my case, it works fine.

 

   

luddet, Newbie
Posted: 26 October 2011 06:54 AM   Total Posts: 4   [ # 2 ]

Thank you! I will try that.
It looks as it might be a problem with away combined with jiglib physics. I can get meshes without any physical connections to lookAt objects but physical meshes seem to break somehow.

 

   

Avatar
Rob Bateman, Administrator
Posted: 06 November 2011 06:26 PM   Total Posts: 120   [ # 3 ]

I’ve just submitted a fix to the lookAt problem on github. please try out the latest build to see if the issues you were experiencing have been fixed!

cheers

Rob

 

   

John Brookes, Moderator
Posted: 06 November 2011 07:04 PM   Total Posts: 732   [ # 4 ]

I miss old lookAt smile)


Little example.

Idea is to have a child object (trident) lookAt some world position while keeping the X axis parallel to the ground.

This works in the old lookat (one that doenst use pointTo)
https://github.com/away3d/away3d-core-fp11/blob/3e1aff496f1df83c046139043e320a205414a102/src/away3d/core/base/Object3D.as

/*
 * This uses lookAt on a child that looks at a world position.
 * Childs X axis (big red arrow) always parallel with the ground
 */

package 
{
 import away3d
.cameras.lenses.PerspectiveLens;
 
import away3d.containers.ObjectContainer3D;
 
import away3d.containers.Scene3D;
 
import away3d.containers.View3D;
 
import away3d.controllers.HoverController;
 
import away3d.debug.AwayStats;
 
import away3d.debug.Trident;
 
import away3d.primitives.WireframeGrid;
 
import flash.display.Sprite;
 
import flash.display.StageAlign;
 
import flash.display.StageScaleMode;
 
import flash.events.Event;
 
import flash.events.MouseEvent;
 
import flash.geom.Matrix3D;
 
import flash.geom.Vector3D;
 
 public class 
PointAtTest extends Sprite 
 {
  
private var view:View3D;
  private var 
scene:Scene3D;
  
//camera controls
  
private var camController:HoverController;
  private var 
move:Boolean false;
  private var 
lastPanAngle:Number;
  private var 
lastTiltAngle:Number;
  private var 
lastMouseX:Number;
  private var 
lastMouseY:Number;
  
  
  private var 
container:ObjectContainer3D;
  private var 
childObject:Trident;
  private var 
lookAtVector:Vector3D;
  
  public function 
PointAtTest():void 
  {
   
if (stageinit();
   else 
addEventListener(Event.ADDED_TO_STAGEinit);
  
}
  
  
private function init(e:Event null):void 
  {
   removeEventListener
(Event.ADDED_TO_STAGEinit); 
   
// entry point
   
stage.scaleMode StageScaleMode.NO_SCALE;
   
stage.align StageAlign.TOP_LEFT;
   
   
   
int3D();
   
initObjects();
   
initListeners();
  
}
  
  
private function int3D():void 
  {
   view 
= new View3D();
   
view.backgroundColor 0x0
   addChild
(view);
   
   
scene view.scene ;
   
   
camController = new HoverController(view.cameranull0);
   
camController.yFactor 1;
   
camController.steps 32
   camController
.minTiltAngle = -90
   camController
.distance 1500
  }
  
  
private function initObjects():void 
  {
   
var grid:WireframeGrid = new WireframeGrid(10100020x0,null,true);
   
scene.addChild(grid);
   
   
container = new ObjectContainer3D();
   
container.rotationX 20;
   
container.= -200;
   
container.200;
   
container.= -200;
   
scene.addChild(container);
   
   
//just for show
  // var containerTrident:Trident= new Trident(400);
  // container.addChild(containerTrident);
   
   
   
childObject = new Trident(2000);
   
childObject.200
   container
.addChild(childObject);
  
  
}
  
  
private function handleEnterFrame(e:Event):void 
  {
   
if (move{
    camController
.panAngle 0.3 * (stage.mouseX lastMouseX) + lastPanAngle;
    
camController.tiltAngle 0.3 * (stage.mouseY lastMouseY) + lastTiltAngle;
   
}
   
   
   
//some movement
   
container.moveForward(1)
   
container.rotationY +=0.5
   container
.rotationX -=0.5
   
   lookAtVector 
= new Vector3D(-5000, -500);
   var 
m3:Matrix3D container.transform.clone();
   
m3.invert()
   
lookAtVector Matrix3D(m3).transformVector(lookAtVector.clone());
   var 
up:Vector3D Matrix3D(m3).deltaTransformVector(new Vector3D(0,1,0));
   
childObject.lookAt(lookAtVectorup); 
   
   
view.render();
  
}
  
  
private function onMouseDown(event:MouseEvent):void
  {
   lastPanAngle 
camController.panAngle;
   
lastTiltAngle camController.tiltAngle;
   
lastMouseX stage.mouseX;
   
lastMouseY stage.mouseY;
   
move true;
   
stage.addEventListener(Event.MOUSE_LEAVEonStageMouseLeave);
  
}
  
  
/**
   * Mouse up listener for navigation
   */
  
private function onMouseUp(event:MouseEvent):void
  {
   move 
false;
   
stage.removeEventListener(Event.MOUSE_LEAVEonStageMouseLeave);
  
}
  
  
private function onMouseWheel(event:MouseEvent):void
  {
   camController
.distance -= event.delta 10;
   
trace(camController.distance)
  
}
 
  
  
/**
   * Mouse stage leave listener for navigation
   */
  
private function onStageMouseLeave(event:Event):void
  {
   move 
false;
   
stage.removeEventListener(Event.MOUSE_LEAVEonStageMouseLeave);
  
}
  
  
private function onStageResize(event Event) : void
  {
   view
.width stage.stageWidth;
   
view.height stage.stageHeight;
  
}
  
  
private function initListeners():void 
  {
   addEventListener
(Event.ENTER_FRAMEhandleEnterFrame);
   
stage.addEventListener(MouseEvent.MOUSE_DOWNonMouseDown);
   
stage.addEventListener(MouseEvent.MOUSE_UPonMouseUp);
   
stage.addEventListener(MouseEvent.MOUSE_WHEELonMouseWheel);
   
stage.addEventListener(Event.RESIZEonStageResize);
  
}
 }
 

 

   

John Brookes, Moderator
Posted: 07 November 2011 03:52 PM   Total Posts: 732   [ # 5 ]

“original away3d lookat code has been reinstated”

Rob, lookAt still fails on the Z with that.

If I use this old version of lookAt
https://github.com/away3d/away3d-core-fp11/blob/3e1aff496f1df83c046139043e320a205414a102/src/away3d/core/base/Object3D.as

Only one (z=0 x=0) north pole fails. Which has always been the case.

The latest commit still fails on all z=0


just remembered I use the old hoverDragControl camera thing from the examples not included in rar

 

File Attachments
src.rar  (File Size: 5KB - Downloads: 0)
   

Avatar
Rob Bateman, Administrator
Posted: 08 November 2011 05:39 PM   Total Posts: 120   [ # 6 ]

how about the “further fix to lookat code” commit? wink

 

   

John Brookes, Moderator
Posted: 08 November 2011 06:24 PM   Total Posts: 732   [ # 7 ]

Yep that works smile

Wonders what the //ridiculous matrix error is

 

   

Avatar
Rob Bateman, Administrator
Posted: 09 November 2011 01:16 AM   Total Posts: 120   [ # 8 ]
JohnBrookes - 08 November 2011 06:24 PM

Wonders what the //ridiculous matrix error is

for more info on that, you can look here wink

https://bugbase.adobe.com/index.cfm?event=bug&id=3021531

 

   

ANDI, Newbie
Posted: 17 July 2013 12:37 PM   Total Posts: 4   [ # 9 ]

In my example the same error occurs.

I thought about manually rotatting the camera with
camera.rotationX and camera.rotationY
But it does not work.

here is my code:

var cameraRotatorX:Number stage.width mouseX;
    var 
cameraRotatorY:Number  =  stage.height mouseY;
    
cameraRotatorY += 0.0+cameraRotatorY/100 ;
    
cameraRotatorX += 0.0+cameraRotatorX/100 ;
    
   
    
camera.=   Math.sin(  cameraRotatorX  180 Math.PI  ) * cameraDis;  
  
      
camera.Math.sin(cameraRotatorY 180 Math.PI) * cameraDis;
    
camera.=    Math.cos(- cameraRotatorX 180 Math.PI) *   Math.cos(cameraRotatorY 180 Math.PI)   *     cameraDis
   
// camera.lookAt(new Vector3D(  ) );
     
camera.rotationX =180-cameraRotatorX;
     
camera.rotationY 180 +   cameraRotatorY

does someone know about using camera.rotationZ ?

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X