Jump to content

[SOLVED] Updateing object position from UnigineScript does not propogate


photo

Recommended Posts

I have some Unigine Script moving some dummy targets around in the world. My "chaser" is programmed to move toward the target. If I move the target manually using the editor functions then it works OK. But if I move the target from UnigineScript the "chaser" never sees the updated position.

 

I have tried adding engine.world.updateSpatial calls before the update but that does not seem to do it.

 

I am setting the target position by calling setWorldPosition() and I have tried setPosition() but still the code does not "see" the updated position of the target. 

 

I'm clearly doing something wrong, but I can't seem to figure it out.

 

Link to comment

mupE.cpp

 

Code attached. It's a bit more verbose than it should be as I'm "snapping" the movement to 45 degree increments, but it demonstrates what I'm seeing.

 

I'm pretty sure I'm missing something simple, but for the life of me I can't see it.

 

Cheers.

Link to comment

I can see one obvious problem  - you effectively have multiple representations of the chaser position and they are not kept in sync (i.e. you have a member variable called "position" and the position of the mesh itself) . That position variable is initialised but never updated, but it's used in your getAngleTo() function which will give the wrong result. 

 

Remove that needless member variable and follow the DRY software engineering principle http://en.wikipedia.org/wiki/Don't_repeat_yourself

:)

Link to comment
×
×
  • Create New...