help with animation sounds

Posted By: jrg

help with animation sounds - 07/01/07 03:45

I used the Au Magazine camera code and changed it up a bit. I want my character to
make a sound each time a foot touches the floor. I have no idea on where to start.

Code:
 //////////////////////////////////////////////////////////////

var video_mode = 7; // 800x600 pixels
var video_depth = 32; // 32 bit mode
var video_screen = 1; // start the engine in full screen mode

////////////////////////////////////////////////////////////////////////////////////

string work28_wmb = <chartest.wmb>;
////////////////////////////////////////////////////////////////////////////////////

function isometric_camera();


////////////////////////////////////////////////////////////////////////////////////

function main()
{
level_load (work28_wmb);
wait (3); // wait until the level is loaded
// call the desired camera function here
isometric_camera();
walk_sounds();
}


function isometric_camera() // displays the player from an isometric view aka 3rd person view
{
while (player == null) {wait (1);} // wait until the player is created
camera.tilt = -15; // look down at the player, play with this value
while (1)
{
camera.x = player.x - 150 * cos(player.pan); // 250 = distance between the player and the camera, play with this value
camera.y = player.y - 150 * sin(player.pan); // use the same value here
camera.z = player.z + 80; // place the camera above the player, play with this value
camera.pan = player.pan; // the camera and the player have the same pan angle
wait (1);
}
}

function walk_sounds()
{
if ((key_w == 1))
{ wait(60);
ent_playsound(me,thud,60);
}
}

starter tunes()
{
var current_track = 1;

while (1)
{

if (current_track == 1)
{
media_play("TOFTIM.wav", null, 100);
}

while (snd_playing(media_handle) != 1) {wait (1);}
sleep (1);
}
}
action players_code
{
var anim_percentage; // animation percentage
var movement_speed; // player's movement speed
var distance_to_ground; // the distance between player's origin and the ground
player = my; // I'm the player
while (1)
{

my.pan += 6 * (key_a - key_d) * time; // rotate the player using the "A" and "D" keys
vec_set (temp.x, my.x); // copy player's position to temp
temp.z -= 5000; // set temp.z 5000 quants below player's origin
distance_to_ground = c_trace (my.x, temp.x, ignore_me | use_box);
movement_speed.x = 9 * (key_w - key_s) * time; // move the player using "W" and "S"
movement_speed.y = 0; // don't move sideways
movement_speed.z = - (distance_to_ground - 17); // 17 = experimental value
movement_speed.z = max (-35 * time, movement_speed.z); // 35 = falling speed
c_move (my, movement_speed.x, nullvector, glide); // move the player
if ((key_w == off) && (key_s == off)) // the player isn't moving?
{
ent_animate(my, "stand", anim_percentage, anm_cycle); // play the "stand" animation
}
else // the player is moving?
{
ent_animate(my, "walk", anim_percentage, anm_cycle); // play the "walk" animation
}
anim_percentage += 10 * time; // 5 = animation speed
if(MY.frame == "walk2") { ent_playsound(ME,thud,60); }


wait (1);
}
}



If anyone can help me with this please respond.
Posted By: tompo

Re: help with animation sounds - 07/01/07 06:59

f.e. you can do it with vec_for_vertex function + c_trace function in loop.

so if vertex (on the bottom of the heel) touches the ground (result of c_trace from this vertex to the ground is small), play sound.

Simple code
Code:
 
var heel_p[3]; var heel_l[3];
sound foot_step = <step.wav>;

function walk_sound
{
while(me)
{
//right foot
vec_for_vertex(heel_p,me,150); //check what vertex is correct to your model
temp.x = heel_p.x;
temp.y = heel_p.y;
temp.z = -500;
c_trace(heel_p,temp,ignore_me);
if(result <=2) //play with this value
{
if ((key_w == 1) || (key_s == 1)) //play sound only when walking
{
ent_playsound (me, foot_step, 200); //play with 200
}
}

//left_foot
vec_for_vertex(heel_l,me,100);
temp.x = heel_l.x;
temp.y = heel_l.y;
temp.z = -500;
c_trace(heel_l,temp,ignore_me);
if(result <=2)
{
if ((key_w == 1) || (key_s == 1)) //play sound only when walking
{
ent_playsound (me, foot_step, 200); //play with 200
}
}
wait(1);
}
}



You can add to c_trace scan_texture mode, to check what kind of floor is below the entity.
if (str_cmpi(tex_name,"grass")==1){play grass.wav}; etc


Simplest way:
You can do this checking animation percentage or frame number.
Check in med in which frame your model put the heel on the ground an then
if(my.frame == 10) || (my.frame == 20){play sound;}

Cheers
Posted By: jrg

Re: help with animation sounds - 07/01/07 17:52

Thank you very much
Posted By: jrg

Re: help with animation sounds - 07/01/07 22:05

I have updated the code but still no sound , maybe i am using the "if" function wrong?

code:

//////////////////////////////////////////////////////////////

var video_mode = 7; // 800x600 pixels
var video_depth = 32; // 32 bit mode
var video_screen = 1; // start the engine in full screen mode

////////////////////////////////////////////////////////////////////////////////////

string work28_wmb = <chartest.wmb>;
SOUND tap2 = <tap.wav>;
////////////////////////////////////////////////////////////////////////////////////

function isometric_camera();


////////////////////////////////////////////////////////////////////////////////////

function main()
{
level_load (work28_wmb);
wait (3); // wait until the level is loaded
// call the desired camera function here
isometric_camera();

}



function isometric_camera() // displays the player from an isometric view aka 3rd person view
{
while (player == null) {wait (1);} // wait until the player is created
camera.tilt = -15; // look down at the player, play with this value
while (1)
{
camera.x = player.x - 150 * cos(player.pan); // 250 = distance between the player and the camera, play with this value
camera.y = player.y - 150 * sin(player.pan); // use the same value here
camera.z = player.z + 80; // place the camera above the player, play with this value
camera.pan = player.pan; // the camera and the player have the same pan angle
wait (1);
}
}


starter tunes()
{
var current_track = 1;

while (1)
{

if (current_track == 1)
{
media_play("TOFTIM.wav", null, 20);
}

while (snd_playing(media_handle) != 1) {wait (1);}
sleep (1);
}
}
action players_code
{
var anim_percentage; // animation percentage
var movement_speed; // player's movement speed
var distance_to_ground; // the distance between player's origin and the ground
player = my; // I'm the player

while (1)
{

my.pan += 6 * (key_a - key_d) * time; // rotate the player using the "A" and "D" keys
vec_set (temp.x, my.x); // copy player's position to temp
temp.z -= 5000; // set temp.z 5000 quants below player's origin
distance_to_ground = c_trace (my.x, temp.x, ignore_me | use_box);
movement_speed.x = 9 * (key_w - key_s) * time; // move the player using "W" and "S"
movement_speed.y = 0; // don't move sideways
movement_speed.z = - (distance_to_ground - 17); // 17 = experimental value
movement_speed.z = max (-35 * time, movement_speed.z); // 35 = falling speed
c_move (my, movement_speed.x, nullvector, glide); // move the player
if ((key_w == off) && (key_s == off)) // the player isn't moving?
{
ent_animate(my, "stand", anim_percentage, anm_cycle); // play the "stand" animation
}

else // the player is moving?
{
ent_animate(my, "walk", anim_percentage, anm_cycle); // play the "walk" animation
}

anim_percentage += 10 * time; // 5 = animation speed

if(my.frame == 4) { ent_playsound(me,tap2,100);}

wait (1);
}
}

code:
© 2023 lite-C Forums