Help on glitch.
Blitz3D Forums/Blitz3D Beginners Area/Help on glitch.
| ||
There a glitch in my game that I can not figure out. There are two cars one is contoled by the host and the other is controled by the guest. I have the cars position being updated eveer 1 secound. When the other computer receives the new enemy postion it places the car where it should be but on the 2nd time the position updated the enemy car is positioned somewhere around 0,1,0 but on the third time the enemy is positioned where it is sopose to be and ect. Here my code can you tell me what I am doing wroung. |
| ||
Dumb question - but have you commented out the Millisecs() timer part of you code in the main loop? You said you think the problem is there...first up -does it run okay without it? |
| ||
..Also - isn't better to updateworld then renderworld? You have it backwards which doesn't make sense to my unedumacted, humble, back-woods, superstitous, canker riddled, peasant-self. Cough.. |
| ||
FYI, try using the forum codes when posting code:What are the forum codes? I found your problem. You are using POSITIONEntity, not MOVEEntity in your online function. The use of PositionEntity is fine (and desired since you want to correct any error that has occured) but you are using it incorrectly. Take note that when a Net message is sent you set the players position to 0, 1, NetMsgData(). Well, it's no wonder that it's at 0, 1, is it? I also noticed that you are splitting the players position up into two messages. Bad idea. What if one is lost? Send them both at the same time. You will have to combine the X and Z and then decipher the X and Z to do it though. So change this: If updatepos + 1000 < MilliSecs() <<<This is where the new postion is sent out. I also think the problem is here. SendNetMsg 69,EntityX#(cam_piv),playerid,0 SendNetMsg 70,EntityZ#(cam_piv),playerid,0 updatepos = MilliSecs() EndIfto this; If updatepos < MilliSecs() SendNetMsg 69, PlayerPos$(EntityX#(cam_piv), EntityZ#(cam_piv)), playerid, 0 updatepos = MilliSecs() + 1000 EndIfAnd add this function to your code: Function PlayerPos$(x#, z#) xpos$ = RSet(Left$(x#, 8), 8) zpos$ = RSet(Left$(z#, 8), 8) Return xpos$ + zpos$ End Function And then change this: If NetMsgType() = 69 PositionEntity c2,NetMsgData(),1,0 <<<This is were the enemy postion is updated. EndIf If NetMsgType() = 70 PositionEntity c2,0,1,NetMsgData() EndIfto this: If NetMsgType() = 69 pos$ = NetMsgData() PositionEntity c2, Left$(pos$, 8), 1, Right$(pos$, 8) EndIf |
| ||
Thankyou. It works fine now. |