This is the code I colored the important parts.
var snakemorph = 0;
Entity* snakebod;
function headhit // only do this upon impact!{my.invisible=on;}
{
my.invisible=on;
ent_morph (snakebod, "snakedead.mdl"); bestill=1;
}
action snakehead
{
// 1 is up, -1 is down
my.health=20;
my.gegner=on;
var direction = 1;
var speed = 1;
my.enable_entity=on;
my.enable_impact=on;
MY.EVENT=headhit;
while (1)
{
walk_percent=(walk_percent+5*time)%100;
ent_animate(me,"walk",walk_percent,ANM_CYCLE);
// move ball in the right direction
my.x -= direction * speed;
// change direction if obstacle is in the way
vec_set(temp,my.x);
temp.z+=direction * speed;
trace_mode = IGNORE_ME;
if (trace(my.x, temp) != 0)
{
direction *= -1;
}
wait(1);
}
}
action snakebody
{
snakebod=me; // assign entity snakebod to this models action
// 1 is up, -1 is down
my.health=20;
my.gegner=on;
var direction = 1;
var speed = 1;
while (bestill==0)
{
walk_percent=(walk_percent+5*time)%100;
ent_animate(me,"walk",walk_percent,ANM_CYCLE);
// move ball in the right direction
my.x -= direction * speed;
// change direction if obstacle is in the way
vec_set(temp,my.x);
temp.z+=direction * speed;
trace_mode = IGNORE_ME;
while (bestill==0)
{
my.enable_impact=on; my.event=lev_2_event; break;
}
if (trace(my.x, temp) != 0)
{
direction *= -1;
}
wait(1);
}
}
This is the image what I did was made the whole scorpion in the snake body and for the snake head I made an invisible block so when I jump on the snake head the snake body turns upside down.
btw I know it's not a snake but a scorpion, at first I started to make a snake but decided a scorpion.