problem with PathAnimator

33 views
Skip to first unread message

fran

unread,
Jun 27, 2009, 10:27:42 AM6/27/09
to away3d.dev
Hello, I'm trying to use the PathAnimator (http://away3d.com/tutorials/
tutorial-how-to-use-the-pathanimator-class). Flash (cs4, v10 player,
away 3.3.3), is complaining about referencing to a null object,
here's the code i'm using:


import away3d.animators.PathAnimator;
import away3d.animators.data.Path;
import away3d.containers.*;
import away3d.core.base.*;
import away3d.primitives.*;
import away3d.core.math.*;
import away3d.materials.*;


//setup
var view:View3D = new View3D({x:300, y:200});
addChild(view);


//path definition
var aPath:Array = [
new Number3D(-1000, -1000, -2000),
new Number3D(-1000, 0, 0),
new Number3D(1000, 0, 0),
new Number3D(1000, 1000, -2000)];
var p:Path = new Path(aPath);


//object to travel path
var mat:IMaterial = new BitmapMaterial(new BitmapData(64,64, false,
0xFF0000));
this.cube = new Cube({material:mat, width:200, height:80, depth:100});
view.scene.addChild(this.cube);



//animator definition
var init:Object = { duration:5000,
lookat:false,
aligntopath:true,
targetobject:null,
offset:new Number3D(0,100,0),
rotations:null,
fps:24,
easein:false ,
easeout:false};
//var pathanimator = new PathAnimator
var pathanimator = new PathAnimator(p, this.cube, init);


//cube @ 50% of path
this.pathanimator.update(0.5);
view.camera.lookAt(this.cube.position);
view.render();



According to debugger, offending line is:
this.pathanimator.update(0.5);

What am I doing wrong?

Thanks in advance.

Fran.

Fabrice3D

unread,
Jun 28, 2009, 5:43:13 PM6/28/09
to away3...@googlegroups.com
I haven't tested your code, but i see in path definition an error that
might be teh triiger of the error
the Path needs CurveSegments objects, this is at least how its stores
the path data internally.

the CurveSegemt objects do require 3 Numbers3D's

compare the system to the curveTo native of flash, its also requires 3
params

k, so back to your code.


> //path definition
> var aPath:Array = [
> new Number3D(-1000, -1000, -2000),
> new Number3D(-1000, 0, 0),
> new Number3D(1000, 0, 0),
> new Number3D(1000, 1000, -2000)];
> var p:Path = new Path(aPath);

should be

> //path definition
> var aPath:Array = [

> new Number3D(-1000, -1000, -2000), --> start poit first segment
> new Number3D(-1000, 0, 0), --> directional point first segment
> new Number3D(1000, 0, 0), --> end point first segment
3 params: ok

and now things go wrong
> new Number3D(1000, 1000, -2000)];
you miss 2 points!

the second segment must first start with last point of previous one
> new Number3D(1000, 0, 0),
a directional point
> new Number3D(1000, 500, -1000);
and the last point
> new Number3D(1000, 1000, -2000)];


I have no idea what the curve must look like, but i'm sure that if you
respect the rule
of 3 params, you will get no errors, and the animation will follow
your curve

if you write a loop, the repeats of the third params for the next one,
is just a matter of saving the Number3D instance, instead
of making new ones, for your curve its not a big problem, but if your
curve are complex, you better reuse instead of creating new ones.

I hope this is the fix to your problem.

Fabrice

fran

unread,
Jun 29, 2009, 9:41:06 PM6/29/09
to away3d.dev
Hi Fabricem thanks again!

It indeed worked after commenting the extra number3D. I was following
the tutorial at the away3D site, however I failed to see I needed the
3 parameters per segment. Best regards.

Fran.

Jensa

unread,
Jun 30, 2009, 9:52:27 AM6/30/09
to away3d.dev
I too had this problem. Maybe we could make the PathAnimator throw an
error if the number of path elements are incorrect? Something that is
more sensible than a 1009 error?

J

Fabrice3D

unread,
Jun 30, 2009, 10:24:47 AM6/30/09
to away3...@googlegroups.com
yes, good idea...

Fabrice

Reply all
Reply to author
Forward
0 new messages