Using tween library

Cannot read property 'getPosition' of undefined

Please check the result of console.log(this.targets); and console.log(this.targetIndex);.

Vec3 {x: 0, y: 0, z: 0}

‘undefined’

So where do you set the targets and where do you set the index? What are the targets?

in initialize and it is also defined in function smoothLookAt

this.targets = this.app.root.findByName('Point '+ this.Point.toString());

I think I understand what you try to do there but I’m not sure if it works that way. And where do you set this.targetIndex?

in initialize function and at the end of smoothLookAt, i have the same script attached on my camera and there is no problem

There is no this.targetIndex in the initialize function of this script.

i have added it moment ago

So the errors are gone?

Cannot read property 'getPosition' of undefined :upside_down_face: :upside_down_face:

If you get an error like that you have to debug why it’s undefined. Mostly because you are using something that doesn’t exist or it exist on a place that the script not read (yet).

1 Like

image

You can click on the orange line and see the script + line that is causing the error. Then you can check if you set it up correctly.
Try to use console.log("myInformation: "+myVariable) to output variables and states :slight_smile:

1 Like

console.log(this.app.root.findByName('Point '+ this.Point.toString()));

  1. Entity {_callbacks: {…}, _callbackActive: {…}, name: “Point 1”, tags: Tags, _labels: {…}, …}

It doesnt have a problem with finding the object, so how can it not get position of this object

edit: i also tried this:
console.log(this.app.root.findByName('Point '+ this.Point.toString()).getLocalPosition());

and console output was: Vec3 {x: -6.879401169177076, y: 6.1988701820373535, z: -23.416128158569336}

Hi @smokys,

you are letting us solve your problems. You should try to solve these yourself. I will happily help you along the way but you will have to put some effort into it.

There are initialization problems that keep recurring and you are not learning to debug these issues. Is it a scope (local/global) problem? Maybe the initialization is wrong. Are you logging the variable just before you try to access the position?

You are able to make some assumptions and debug the probabilities. Try something :slight_smile:

1 Like

i would not create this topic if i didnt try what i can

No problem @smokys, we all started somewhere :slight_smile:

Don’t you think your ambitions are a little too high? Maybe start a bit smaller, learn and progress along the way.

I don’t want to discourage you but to be frank: you are failing with the most basic understanding of script behavior.

Here is a Script explanation.

Try to learn to use the Google Developer Tools Debugger (F12):

2 Likes

Yeah its truth that i put lots of basic things here but thats the actually one of good ways of learning, it really hepls me when i can ask people and communicate about it, also there are plenty people similiar to me who will find these topics useful, i tried basic thins ,nw its time to get bigger

The problem is not in your targets, but in the fact that this.lookTo is not defined anywhere. A method .copy() is used on a vector, so define a vector first, save it in this.lookTo, then you can copy other vectors to it.

// in initialize()
this.lookTo = new pc.Vec3();

I already said that @LeXXik. That was indeed the first problem in that line. The next problem in that line is the target.

1 Like