Help! Tell me what's happening here!

Blitz3D Forums/Blitz3D Programming/Help! Tell me what's happening here!

Here's a really odd thing! I apparently have an integer
value which changes of its own accord...
or perhaps some strange Blitz blip not adding correctly.

Let me explain:

In my game ( a side scrolling platformer) the player can
only turn left or right - 90 or 90 degrees ie.
only 180 degrees either way. On land his 'turn' variable
is set to 12 degrees...in water he turns slower at 6 degrees.
Note that both integer values neatly divide into 180.

The problem I have is that the rotations are going out of
synch by strange steps - 10, 15 etc and then they remain
screwed up!!

Please look at the screen shot - the debuglog tells it all
and captures the moment when the rotations go weird.

Environment tells me where I am :
2 is in water
1 is on land
-1 is a special water exit routine that will finish off
any on going 'left or right' rotations whilst leaping out
of the water (or simply process any new turns as usual
that may have been initiated). These need to be completed
as the 'turn' value will change to 12 on land and would not
otherwise finish rotating either on -90 or 90 degrees if
the two different turn values are intermingled during a
single Y rotation.

Water & Special rotations tells me the player's Y rotation
value and it's by reading down this list we can spot a
turn in progress and then see it go out of synch! ..and
this even while the actual turn value is displayed as a
correct number; in this case '6'.

Read down far right numbers on the list until you come to
97! It's bloody impossible!! I'm supposed to be adding 6
to the value of 90 and get 97???

Can anybody tell me what's going wrong here? It's got me
chewing the desk I'm at here!

Could tweening upset these calculations at all? Though it
simply doesn't show in the debuglog.




Can we see some code?

> Could tweening upset these calculations at all?

If you are tweening then the answer is yes. If you are actually using fractional variables to handle the tweening then the imprecision of floating point will cause this problem.

Although seeing the code will certainly help to prove it or not.

Okay - sorry for not putting relevant code here in the first place - here's the actual 'special water exit' function that sends the rotations out of synch. Dynaman - if it is the tweening what can I do
to get this working right?

; ------------------------
; ALLOWS TOMMY TO JUMP FROM WATER
; ------------------------
FUNCTION special_exit_routine ()
;---------------
IF exit_switch=-1 ; this is set IF near 'Water_door' AND the up key is being pressed FOR more than a 1/4 second

	;hide the water collison mesh so collisions are off
	M_trady#=0.89 ;reset collision ellipses to upright
	M_tradx#=0.50
	enemy_bounce=0
	bounce_up#=0
	bounce_boost#=0
	jump_boost#=0


	HIDEENTITY water_bound
	exitposy#=posy#
	exit_switch=-2
	IF KEYDOWN(left) OR KEYDOWN(right) ; NOT moving fORward or backwards
		anim_trig=20 ;set up FOR anims below = leap forward
	ELSE
		anim_trig=25 ; = leap up
	ENDIF
ENDIF
IF exit_switch=-2
	exittime=exittime+3
	trans_y#=0
ENDIF
IF exittime=>90
	exittime=0
	environment=1 ; switch TO land
	exit_switch=0
	IF KEYDOWN(left) OR KEYDOWN(right)
		anim_trig=1 ; RUN
	ELSE
		anim_trig=20 ; STAND
	ENDIF
ENDIF
temp_posy#=((SIN(exittime)*3)+ exitposy#)
;------------------
IF environment = -1
	IF exittime=60
		IF KEYDOWN(left) OR KEYDOWN(right)
			anim_trig=30
		ELSE
			anim_trig=35
		ENDIF
	ENDIF

	IF anim_trig=20
		anim_trig=0
		ANIMATE tommy,3,0.35,water_leap_forward,15

	ENDIF

	IF anim_trig=25
		anim_trig=0
		ANIMATE tommy,3,0.35,water_leap_up,15

	ENDIF

	IF anim_trig=30
		anim_trig=0
		ANIMATE tommy,3,0.35,jump_run_anim2,8
		ENTITYRADIUS player, 0.49,0.79
	ENDIF
	IF anim_trig=35
		anim_trig=0
		ANIMATE tommy,3,0.35,jump_up_anim2,8
		ENTITYRADIUS player, 0.49,0.79
	ENDIF



	;-----------------------------------------------------------
	;-----------------
	; turn the player
	;------------------

	IF turn_tom="right"
		IF NOT roty  =-90
			turn=turn
			TURNENTITY targetnode,0,turn,0

		ENDIF
	ENDIF
	IF turn_tom="left"
		IF NOT roty = 90

			TURNENTITY targetnode,0,turn,0

		ENDIF
	ENDIF
	
	;-----------------------------------------------------------

	IF  KEYDOWN( right ); RIGHT. The 'D' AND 'CURSOR RIGHT' keys.
		;IF roty=90 ;remember i've rotated the tommy model To -90 To make him stand sideways
			;turn_tom="right"
			;turn=6
		;ELSE
			;turn=turn
		;ENDIF
		move_x#=move_x#+0.002 * speedup#
		IF move_x#=>0.012 * speedup#
			move_x#=0.012 * speedup#
		ENDIF

	ENDIF
	;-----------------------------------------------------------
	IF  KEYDOWN( left ) ;LEFT. The 'A' AND 'CURSOR LEFT' keys.
		;IF roty=90 ;remember i've rotated the tommy model To -90 To make him stand sideways
			;turn_tom="left"
			;turn=6
		;ELSE
			;turn=turn
		;ENDIF
		move_x#=move_x#-0.002 * speedup#
		IF move_x#=< -0.012* speedup#
			move_x#=-0.012* speedup#
		ENDIF
	ELSE
	ENDIF

	;----------------------------

   roty=ENTITYYAW(targetnode) ; grab this value because I   need it FOR the 'X' bob effect at the bottom of FUNCTION


	if EntityPitch(targetnode,true) < 0
		dturnx#=1
		tempturn#=EntityPitch(targetnode,true)+dturnx#
		bobturn#=tempturn#	
	endif

	if EntityPitch(targetnode,true) > 0
		dturnx#=1
		tempturn#=EntityPitch(targetnode,true)-dturnx#
		bobturn#=tempturn#	
	endif

	if EntityPitch(targetnode,true) > -1 and  EntityPitch(targetnode,true) < 1 then bobturn#=0


	;-------------------------------------------------------------------
	ROTATEENTITY targetnode,bobturn#,roty,0 ,true ; Roty is grabbed from the turn section above
	TRANSLATEENTITY player,((move_x#+ jumpboost#) * player_move_speed#) , trans_y#, 0
	POSITIONENTITY player_camera, 0, (camypos#+3.24),campos#, FALSE
	;-------------------------------------------------------------------
	posx#=ENTITYX (player)
	posy#=ENTITYY(player)
	posz#=ENTITYZ(player) ;we don't want tommy To be off his zero z
	rotx=ENTITYPITCH(player)
	roty=ENTITYYAW(targetnode)
	rotz=ENTITYROLL(player)
	;If posz#<>0
	POSITIONENTITY player, posx#, temp_posy#, 0 ; KEEP the Z at ZERO!!
	;EndIf
ENDIF
;------------------
FLUSHKEYS




;---------------------------
do_bullets()
player_recoils()
;---------------------------

;debuglog " Special rotations Y :  " + roty

END FUNCTION



Anybody have any ideas?

I had a problem similar to this, I switch from 'tweening' to 'delta T' and it solved the synchro problems.
Otherwise, if you prefer to use tweening, try to position the object after updateworld.

Thanks - I'll look into that