So I am doing something I never thought I'd do. I basically am asking you guys for actual code. So I already have code given by a friend, but it's just horrible for npcs. When the npc follows players to go and attack them they are literally 1 tile behind them always. I try to use delay to slow them down but it just makes them have very jerky movements. This code uses a speed var to determine players movement speed. It works perfectly for players but when it comes to npcs and mobs it is just all wrong.
|
I would also like to point out, besides Tile and Pixel, there's also three styles of directional movement most BYOND games choose from. I don't recall what the exact terms are but I'll call them Directional, Omnidirectional, and semi-omnidirectional.
Directional is the standard direction movement where you can travel in 4 directions (NORTH, SOUTH, EAST, WEST) but must release your current movement to switch directions. (Ex: Moving NORTH and you want to go WEST, you can't go NORTH-WEST so you must release the UP arrow and then press the LEFT arrow.) Semi-Omnidirectional is the direction movement where you can travel in the 8 directions, exactly like directional but you can bunch directions together like UP and LEFT would give you NORTH-WEST and etc. If you run into a horizontal wall while going diagonally, this method will stop you in your tracks. Omnidirectional allows you to smoothly move and switch between the directions without having to fully release keys. This normally coincides with pixel movement, but have seen people stick with semi-omnidirectional instead which causes clunky movement. Whereas, this style movement is very smooth and perfect with pixel-movement. If you run into a horizontal wall while going diagonally, this method will continue your run but by choosing the vertical equivalent of your travel. Ex: Going NORTH-EAST into a wall while still using both NORTH and EAST, will then make you go EAST. Getting back to the issue at hand, it's hard to say what exactly is the problem without seeing your NPC aggro code, your NPC movement code, and your player movement code. If you just want copy+paste code you can check out the library section. http://www.byond.com/ developer/?sort=date&text=tag%3amovement |
At the moment I am using
mob |
When using tile movement, it's common to have a cooldown time between steps as a way of controlling movement speed. This is typically used in conjunction with glide_size to make glides take exactly as much time as the cooldown, to maximize smoothness; when moving constantly, there should be no point where you stand still.
In pixel movement, steps always occur as frequently as possible (every tick) to maximize smoothness and responsiveness. Movement speed is controlled by the number of pixels moved each tick.
Gonna need more details on what your movement needs are. There is no "one size fits all" movement code for you. All games can do it differently.