Tweening/Flick Problem
Blitz3D Forums/Blitz3D Beginners Area/Tweening/Flick Problem
| ||
After reading a recent posting on tweening to get a constant game speed I have given it a go, but I am little stuck now. Tweening works but has an unanticipated effect. In my game if an object gets too far away from the player it get wrapped around to the other side of the player. I use positionentity followed by resetentity to acheive this. And it was all working fine till I implemented the tweening code. You now get glimpses of the objects as they flick past, I kinda understand why this happens but I am a loss on how to stop it. I have tried hiding the entity before the position and showing it after, but this makes not difference (and i kinda understand why this happens too). Any ideas? The offending code looks like this at the moment (just the move bit) For stuff.blitz_obj = Each blitz_obj If Abs(EntityX (stuff\mesh)-EntityX(player_mesh)) > bound Then HideEntity(stuff\mesh) If EntityX (stuff\mesh) < EntityX(player_mesh) Then PositionEntity (stuff\mesh,EntityX(stuff\mesh)+(bound*2),EntityY(stuff\mesh),0) Else PositionEntity (stuff\mesh,EntityX(stuff\mesh)-(bound*2),EntityY(stuff\mesh),0) EndIf ShowEntity(stuff\mesh) ResetEntity stuff\mesh EndIf If Abs(EntityY (stuff\mesh)-EntityY(player_mesh)) > bound Then HideEntity (stuff\mesh) If EntityY (stuff\mesh) < EntityY(player_mesh) Then PositionEntity (stuff\mesh,EntityX,EntityY(stuff\mesh)+(bound*2),0) Else PositionEntity (stuff\mesh,EntityX,EntityY(stuff\mesh)-(bound*2),0) EndIf ShowEntity (stuff\mesh) ResetEntity stuff\mesh EndIf TranslateEntity (stuff\mesh,stuff\xv,stuff\yv,0) Next |
| ||
Try doing any repositioning over a large distance, immediately before the CaptureWorld command. If necessary (and practical), cache the data instructing the program to 'teleport' the object, into a typelist, and process the list before CaptureWorld. Here's some test code I made up using a modified version of the castle demo. It just shows a cube with a collision sphere being moved between two positions. The cube's collision sphere is set up to collide with the player, and visa-versa, so you can walk the player character between the two cube positions to check that no unwanted collision is occuring during the teleport. As you can see, there are no ghost images between the two cube positions, as the cube is being moved immediately before the CaptureWorld command is executed. To run this code, you'll need to create a .bb file in the castle demo folder ( C:\Program Files\Blitz3D\Samples\Blitz 3D Samples\mak\castle ) and place the code in that file. To see the code I've modified for the test, look for code between lines marked with ';******'. |
| ||
Brilliant & Thanks, I split the two functions, updating the position based upon velocity (the translateentity command at the end) and the repositioning code, and ran them a different parts of the main loop, before and after capture world. Works perfectly now. I think my problem is I kinda understand what the tweening code is attempting to do, without really understanding the detail. |