SONIC PATHS - Stickto() Function
Posted: Tue Jun 24, 2008 4:36 am
Version 1 of the stickto function
NOTE: this version is a simple version that uses collisionfree and as such cannot determine the difference between the ground and other objects..
however, it is the simplest version to learn from,
The next version will have the ability to distinguish between the ground and other objects, the demo i posted earlier uses that method, and therefore can ignore the plants ( background sprites) but at the moment uses a secondary sprite in order to allow collsionstate to work properly... i am still working on removing the need for that..)
see viewtopic.php?f=4&t=5847
The next version will also be further optimized to increase speed by using a binary search to more quickly find a "free" angle to move on, and some further code optimization (this version was basically just to make it work). The binary search algorithm will also "even out" the time between frames so that long searches and short searches will take similar times ( no lagging on some frames, although as yet, i don't have any speed problems with it.. )
The stickto() function can be ignored at any time, provided the global variable DirAngle is updated with the players current angle+90. This way the player can jump/fall etc etc and return to ground hugging mode..
(I may yet move the DirAngle into another parameter to pass to the function ..... )
Please start playing with it/experiment with different surfaces, game ideas, etc, and let me know what you want to do with it as far as improving it..
if the code can not be worked out by anyone, let me know and i will do a step by step on "how it works"
there is two global scripts - one fro global variables and one for the function.. and a small script in the draw actor of the player to move him, and that is all..
The main var to play with, is the velocity (in global) - the faster you go the less accurate you are, but because you go faster... you really can't tell anyway..
cheers and have fun with it
Feral
FROM NOTES IN THE GLOBAL SCRIPT
// **********************************
// S T I C K T O
//
// a ground hugging function by feral
// **********************************
// USAGE:
// 1.call before setting angle and directional velocity/
// 2. pass a number or a var for how many degrees to check each step,
// 1 is slowest but more accurate -
// 20 is about max depending on type of ground surface
// higher numbers (on rough surfaces) can get very unpredictable
//
// The directional angle of the actor should then be set to angle=Direangle-90;
// DirAngle is a GLOBAL float VAR
//
// NOTE: currently works best with round sprites...
// although is effective on other shapes depending on game
// to use with odd shaped sprites it is recommended
// to use a round "hidden" sprite as the object of the function
// and overlay the animations as a separate sprite.
//
// THIS IS REVISION 1.0 please check for later versions
//
// later versions will have binary searching to speed up the collision checks
// and an incremental pixel by pixel detection option to avoid moving through thin walls
// it will also be able to distinguish between collision objects .
//
//
NOTE: this version is a simple version that uses collisionfree and as such cannot determine the difference between the ground and other objects..
however, it is the simplest version to learn from,
The next version will have the ability to distinguish between the ground and other objects, the demo i posted earlier uses that method, and therefore can ignore the plants ( background sprites) but at the moment uses a secondary sprite in order to allow collsionstate to work properly... i am still working on removing the need for that..)
see viewtopic.php?f=4&t=5847
The next version will also be further optimized to increase speed by using a binary search to more quickly find a "free" angle to move on, and some further code optimization (this version was basically just to make it work). The binary search algorithm will also "even out" the time between frames so that long searches and short searches will take similar times ( no lagging on some frames, although as yet, i don't have any speed problems with it.. )
The stickto() function can be ignored at any time, provided the global variable DirAngle is updated with the players current angle+90. This way the player can jump/fall etc etc and return to ground hugging mode..
(I may yet move the DirAngle into another parameter to pass to the function ..... )
Please start playing with it/experiment with different surfaces, game ideas, etc, and let me know what you want to do with it as far as improving it..
if the code can not be worked out by anyone, let me know and i will do a step by step on "how it works"
there is two global scripts - one fro global variables and one for the function.. and a small script in the draw actor of the player to move him, and that is all..
The main var to play with, is the velocity (in global) - the faster you go the less accurate you are, but because you go faster... you really can't tell anyway..
cheers and have fun with it
Feral
FROM NOTES IN THE GLOBAL SCRIPT
// **********************************
// S T I C K T O
//
// a ground hugging function by feral
// **********************************
// USAGE:
// 1.call before setting angle and directional velocity/
// 2. pass a number or a var for how many degrees to check each step,
// 1 is slowest but more accurate -
// 20 is about max depending on type of ground surface
// higher numbers (on rough surfaces) can get very unpredictable
//
// The directional angle of the actor should then be set to angle=Direangle-90;
// DirAngle is a GLOBAL float VAR
//
// NOTE: currently works best with round sprites...
// although is effective on other shapes depending on game
// to use with odd shaped sprites it is recommended
// to use a round "hidden" sprite as the object of the function
// and overlay the animations as a separate sprite.
//
// THIS IS REVISION 1.0 please check for later versions
//
// later versions will have binary searching to speed up the collision checks
// and an incremental pixel by pixel detection option to avoid moving through thin walls
// it will also be able to distinguish between collision objects .
//
//