Tail objects following a snake head

Started by Snake, Thu 29/01/2004 03:09:51

Previous topic - Next topic

Snake

I was fooling around today and got an idea for a mini game. I tried making a bionic snake kinda creature as a main character using the FollowCharacterEx command.
What I've got is the snake's head and 4 other body parts (just balls). The best example I can come up with is that Snake Rattle N' Roll game for the NES.
What I want to do is have the "balls" follow tightly behind eachother like a tail.
I haven't put much thought into it script-wise, but I've just been messing with that command.
This is what I've got:
FollowCharacterEx (BA, 0, 2, 1);
FollowCharacterEx (BB, 1, 0, 1);
FollowCharacterEx (BC, 2, 0, 1);
FollowCharacterEx (BD, 3, 0, 1);

BA-D are the balls behind the snake. I've just made it so each ball is following as closley as possible but they don't move quick enough. After the EGO moves it takes a second for them to follow eachother around. Is there a way to make this more smooth? Or would it be out of the way to suggest another option within this command to make the characters follow immediately?

Thank you,


--Snake
PS
Every time I sign into the forums I always select FOREVER, but every time I come here I have to do it again..WTF?? :)

--EDIT--
Oh and before I forget, I'm also using diagonal views (which I've never used before), but when the character goes in a diagonal direction, it's always the side view... What am I missing? The only time it uses the diagonals is when it turns around.

Thanks in advance.
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

Kairus

Maybe you could save the coordinates of your main snake in variables x and y. Then in the repeatedly execute:

if (character[SNAKE].x != x || character[SNAKE].y != y) {
 x = character[SNAKE].x;
 y = character[SNAKE].y;
 MoveCharacter (BD, character[BC].x, character[BC].y);
 MoveCharacter (BC, character[BB].x, character[BB].y);
 MoveCharacter (BB, character[BA].x, character[BA].y);
 MoveCharacter (BA, x, y);
}

That should make the balls move quickly behind each other, but perhaps they will collapse with the main SNAKE, hopefully it will do the right thing if each characters is not marked as "Can be walked through"

Well, if you don't like it and wan't an easier way, did you try using different combinations of parameters for FollowCharacterEx? It says there's an eagerness parameter... did you try setting it to 0?
Download Garfield today!

DOWNLOADINFOWEBSITE

Snake

#2
Yeah. All it does it make them bounce around.

Anyway, thanks for the feedback :) I'll go try it.

--EDIT--
QuoteMaybe you could save the coordinates of your main snake in variables x and y. Then in the repeatedly execute:
How do I save the coordinates in X and Y? I'm not too familiar with the global variable commands. The only ones I remember using were the character(CHARID).walking and character(CHARID).prevroom. It's been so damned long since I scripted anything.
Or, if I'm just confused and was just supposed to copy and paste your code into the rooms repeatedly execute, I tried that and it doesn't know what X and Y are when I save.
Thanks,


--Snake
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

Pumaman

I presume Kairus's script relies on you putting:

int x,y;

at the top of your global script.

Snake

Thanks for putting up with my retardness ;)

This is what it did:
First off it slowed it down quite conciderably when the main snake moved. The balls behind it didn't move until the snake head was stopped completely. I also noticed that they stopped at a large distance between each other and always stopped where the last ball was stopped.

Thanks again for all the help,


--Snake
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

Scorpiorus

#5
Try the next modification of Kairus's idea:

//main global script

#define TIMER_DELAY 10

int timer = TIMER_DELAY;
int goX, goY;

function StopAll() {
 StopMoving(SNAKE);
 StopMoving(TA);
 StopMoving(TB);
 StopMoving(TC);
 StopMoving(TD);
}

function Following() {
 
   StopAll();

   MoveCharacterPath(TD, character[TC] .x, character[TC] .y);
   MoveCharacterPath(TC, character[TB] .x, character[TB] .y);
   MoveCharacterPath(TB, character[TA] .x, character[TA] .y);
   MoveCharacterPath(TA, character[SNAKE].x, character[SNAKE].y);
   MoveCharacterStraight(SNAKE, goX, goY);
     
   timer = TIMER_DELAY;
}

function MoveSnake(int x, int y) {
 goX = x;
 goY = y;
 Following();
}


function repeatedly_execute() {
 // put anything you want to happen every game cycle here

 if (character[SNAKE].walking == 0) StopAll();
 
 if (timer <= 0) {
   if (character[SNAKE].walking) Following();
 } else timer--;
 
}




MoveSnake(int x, int y) function moves snake to x, y. You can put it inside on_mouse_click() to let the player to control the snake.

SNAKE - snake head
TA, TB, TC, TD - characters representing snake's tail

All the characters have to have the same walking speed.

Also I think you need to disable collision detection for them as well as tick do not turn before walking option.

Adjusting TIMER_DELAY regulates the distance between the characters.

Hope this helps :)

~Cheers

SMF spam blocked by CleanTalk