If your making a game, it's VERY likely you will need movement. But, different movements can affect your game and cause lag if not coded efficiently. Here I'm going to tell you how to make a normal movement engine which has virtually no lag (every now and again players may jump depending on pings in server - that's normal).
In part one, you made some funky detectors for your player. Well Done! Firstly, we need to set the positions of the detectors to your player. I assume you know how to do this..
+ Always
- Set position of Up Detector to (0,-9) of Your Player
- Set position of Down detector...
- Set position of left detector...
- Set position of right detector...
- Make detectors invisible
|
Obviously the positions will vary to mind if you have different sized players .etc.
+ Repeat while left arrow is pressed
+ Left detector ISNT overlapping backdrop
- Set value A of Your Player to -1
|
+ Repeat while right arrow is pressed
+ Right detector ISNT overlapping backdrop
- Set value A of Your Player to 1
|
This will be more explainable later - but notice that Value A of your player covers the X directions. Therefore we'll use value B to cover our Y directions.
+ Repeat while up arrow is pressed
+ Up detector ISNT overlapping backdrop
- Set value B of Your Player to -1
|
+ Repeat while down arrow is pressed
+ Down detector ISNT overlapping backdrop
- Set value B of Your Player to 1
|
Now things may get a little confusing here on, I'll try to explain best I can though.
+ Your Player: Value A different to Value C
- Your Player: Set value C to Value A
- MooClick: Channel - Str$( X( "Your Player" ) ) + , + Str$( Y( "Your Player" ) ) + "," + Str$( Alterable Value A( "Your Player" ) ) + , + Str$( Alterable Value B( "Your Player" ) ) on subchannel 0
|
Basically if Value A is different to Value C, then we send our positions. By default, Value C is 0 - therefore if we move left and right, Value A gets set to 1 or -1 - making it different to value C. If the values are different, then we send our positions and set value C to value A (so they are the same again). This is virtually a lag free system, as it only sends our positions when needed too. We also send alterable values A and B which show the players direction and position gap - if you remember, we set these to -1, 1 when pressing keys. If you read part 1, you will know that these are the 3rd and 4th elements - and when retrieved, they are set to values B and C of the other player (remember - value A is already being used for the other player's MOO ID).
+ Your Player: Value B different to Value D
- Your Player: Set value D to Value B
- MooClick: Channel - Send Str$( X( "Your Player" ) ) + , + Str$( Y( "Your Player" ) ) + "," + Str$( Alterable Value A( "Your Player" ) ) + , + Str$( Alterable Value B( "Your Player" ) ) on subchannel 0
|
Exactly the same as above - but this time we use value B for Y positions, and compare it to value D. Hope I haven't confused you here.
+ Your Player: Value A different to 0
- Set x position to (X position) + Value A
|
+ Your Player: Value B different to 0
- Set Y position to (Y position) + Value B
|
If you press an arrow key, then values A and B set to 1 or -1, making them different to 0. If the values are 0, that means your not moving. This basically says that if values A or B are different to 0, then set X pos to A and Y Pos to B. Or, if your pressing a key, making your player move.
+ Other Player: Value B different to 0
- Set x position to (X position) + Value B
|
+ Other Player: Value C different to 0
- Set Y position to (Y position) + Value C
|
This basically makes the player move with almost no lag. If you remember, when a key is pressed - value A and B are set to either 1 or -1. We then send these via string parser (elements 3 and 4) and they a retrieved to another player and set to value B and C. Hope that makes sense!
+ (NEGATE) Repeat while Left key is pressed
- Your Player: Set value A to 0
|
+ (NEGATE) Repeat while Right key is pressed
- Your Player: Set value A to 0
|
+ (NEGATE) Repeat while Up key is pressed
- Your Player: Set value B to 0
|
+ (NEGATE) Repeat while Down key is pressed
- Your Player: Set value B to 0
|
Basically, if the player is pressing no keys - don't make the player's object move. Remember, setting to 0 means the player doesn't move.
|