The idea is to have an object “follow” another object and stay behind it slightly. I am trying to figure out the best way to handle this and have tried many different things over the past couple of days but I can’t get it to work correctly.
The ideal solution would be to group the objects in a container, offset the object, and have the object simply lookAt the other. However, I have physics applied to one of the objects so I don’t think that adding it to the container would work. Right now I have the object with physics separate and a container with the other object that is offset by 10. This works to place the object behind the other but when the lookat is applied, it doesnt seem to look directly at the main object.
var ball:Mesh = new Mesh(new SpereGeometry());
var cube:Mesh = new Mesh(new CubeGeometry());
cube.moveBackward(10);
var container:ObjectContainer3D = new ObjectContainer3D;
scene.addChild(container);
container.addChild(cube);
now in enterFrame…
container.position = ball.position;
cube.lookAt(ball.position);
This code isn’t taken from my program but is a representation of what it is doing.
I would like the cube to lookat the ball regardless of its position. It almost works but it seems the offset it messing with the rotation. The ball needs to move around the screen, being chased by the cube.
Any help is appreciated, thank you for your time.