Animation in While!

Posted By: Moerk

Animation in While! - 12/26/07 19:11

Ich habe ein kleines Random System gebaut, indem eine Zufallszahl zwischen 0 und 1 gewählt. Je nachdem welche Zahl kommt wird eine der beiden Angriffsanimationen abgespielt. Allerdings passiert bei mir da gar nichts bzw. ich sehe meine Charakter kurz "zucken" und mehr kommt nicht.

Dazu muss ich sagen, ich möchte das die Animation mit nur einem Mausklick komplett einmal durchgespielt wird, ohne dass man auf der Maustaste bleiben muss. Deshalb habe ich eine While Schleife genommen.

Hier der Code:

Code:

function attackit
{
randomize();
my.attack_choose = int(random(2));
if(my.attack_choose == 0)
{
while (ani_attack1 <= 100) // Solange ani....
{
ani_attack1 = 8 * time_step; // Ani Speed
ent_animate(my, "attack", ani_attack1, anm_cycle); // Ani Bfehl
wait(1);
}
}
ani_attack1 = 0;
if(my.attack_choose == 1)
{
while (ani_attack2 <= 100) // Solange ani....
{
ani_attack2 = 8 * time_step; // Ani Speed
ent_animate(my, "attack2", ani_attack2, anm_cycle); // Ani Bfehl
wait(1);
}
ani_attack2 = 0;
}
}



Kennt jemand des Lösungsproblem oder gibt es da ne elegantere Methode?
Posted By: Anonymous

Re: Animation in While! - 12/26/07 19:16

versuch mal das:

Code:
 

function attackit
{
randomize();
my.attack_choose = int(random(2));
if(my.attack_choose == 0)
{
while (ani_attack1 <= 100) // Solange ani....
{
ani_attack1 = 8 * time_step; // Ani Speed
ent_animate(my, "attack", ani_attack1, anm_cycle); // Ani Bfehl
ani_attack1 += 3*time;//animation speed
if(ani_attack1 > 100){ani_attack1 = 0;}
wait(1);
}
}
ani_attack1 = 0;
if(my.attack_choose == 1)
{
while (ani_attack2 <= 100) // Solange ani....
{
ani_attack2 = 8 * time_step; // Ani Speed
ent_animate(my, "attack2", ani_attack2, anm_cycle); // Ani Bfehl
ani_attack2 += 3*time;//animation speed
if(ani_attack2 > 100){ani_attack2 = 0;}
wait(1);
}
ani_attack2 = 0;
}
}



Posted By: Slin

Re: Animation in While! - 12/26/07 19:22

Du vergisst einfach nur das addieren:
ani_attack1 = 8 * time_step; // Ani Speed
->
ani_attack1 += 8 * time_step; // Ani Speed

beim anderen natürlich auch.

@Fear411: gewöhne dir mal saubereren code an, zumal deiner auch nicht funktionieren sollte, da ani_attack jedes mal zurückgesetzt wird.
Posted By: Anonymous

Re: Animation in While! - 12/26/07 19:24

sry hab mir den code nicht genau angeschaut
Posted By: Moerk

Re: Animation in While! - 12/26/07 19:29

Funktioniert nicht... ich schätze es liegt an der While Schleife...
Posted By: flits

Re: Animation in While! - 12/26/07 20:52

Code:

function attackit
{
var doit;
while(1)
{
if(doit == 0)
{
randomize();
my.attack_choose = int(random(2));
}
if(my.attack_choose == 0)
{
doit = 1;
if(ani_attack1 <= 100) // Solange ani....
{
ani_attack1 = 8 * time_step; // Ani Speed
ent_animate(my, "attack", ani_attack1, anm_cycle); // Ani Bfehl
wait(1);
}
else{doit =0;}
}
ani_attack1 = 0;
if(my.attack_choose == 1)
{
doit = 1;
if(ani_attack2 <= 100) // Solange ani....
{
ani_attack2 = 8 * time_step; // Ani Speed
ent_animate(my, "attack2", ani_attack2, anm_cycle); // Ani Bfehl
wait(1);
}
else{doit =0;}
ani_attack2 = 0;
}
wait(1);
}
}


Posted By: frazzle

Re: Animation in While! - 12/26/07 21:25

Try this :

Code:

function attackit
{
while(player != null)
{
ani_attack1_speed = 8;
ani_attack2_speed = 8;
randomize();
my.attack_choose = int(random(2));
if(my.attack_choose == 0)
{
while (ani_attack1 < 100) // Solange ani....
{
ani_attack1 += (ani_attack_speed * time_step)%100; // Ani Speed
ent_animate(my, "attack", ani_attack1, 0); // Ani Bfehl
wait(1);
}
ani_attack1 = 0;
}
if(my.attack_choose == 1)
{
while (ani_attack2 < 100) // Solange ani....
{
ani_attack2 += (ani_attack2_speed * time_step)%100; // Ani Speed
ent_animate(my, "attack2", ani_attack2, 0); // Ani Bfehl
wait(1);
}
ani_attack2 = 0;
}
wait(1);
}
}



If this doesn't work, try changing the 100 value into 99.

Cheers

Frazzle
Posted By: Moerk

Re: Animation in While! - 12/26/07 21:41

Well ok but i start that script in another while loop

Code:
if(mouse_left && proc_status(attackit) == 0)
{
attackit();
}



the while loop isnt a good solution in this way!
Posted By: rvL_eXile

Re: Animation in While! - 12/27/07 02:29

Schau mal auf meinem Blog unter Tutorials "player with Animation Tutorial" dort wirst du sehen wie es geht

cYa Sebastian

P.S. Blog siehe Signatur
Posted By: Slin

Re: Animation in While! - 12/27/07 13:00

Quote:

Schau mal auf meinem Blog unter Tutorials "player with Animation Tutorial" dort wirst du sehen wie es geht

cYa Sebastian

P.S. Blog siehe Signatur



Sorry, aber den code kann man vergessen... Gerade wenn es darum geht etwas abzugucken.

Mir ist noch die Idee gekommen, dass es sein könnte, dass die Funktion für diese Animation zu häufig aufgerufen wird und die Animation also in kürzester Zeit abläuft.
Dies passiert nähmlich durch
if(key_kp)
{
funktion();
}
in einer Schleife.
Um das zu verhindern könntest du z.B. eine Variable setzen solange die Funktion ausgeführt wird und erst, wenn diese wieder 0 ist die Funktion erneut aufrufen lassen.
Posted By: Moerk

Re: Animation in While! - 12/27/07 14:55

Habe ich bereits gemacht! Das funktioniert... allerdings verwende ich die Methode

"proc_status(function) == 0"

bevor er das überhaupt startet. Das Problem habe ich vor kurzem in einem anderen Thread behandelt.

Jetzt geht das eben nur bis zu diesem bestimmten Teil (ANimationen) Das ist mein neues Problem

Aber jetzt erstmal VIELEN DANK an alle bisher für die Hilfe ich schau mal im Blog nach und geb dann nochmal Bescheid..
Posted By: frazzle

Re: Animation in While! - 12/27/07 15:16

Quote:

Well ok but i start that script in another while loop

Code:
if(mouse_left && proc_status(attackit) == 0)
{
attackit();
}



the while loop isnt a good solution in this way!




Maybe you could call the function( attackit(); ) out of the while loop from the action you're using it in and set the if statement ( if(mouse_left && proc_status(attackit) == 0) ) inside the while loop of the initial function ( attackit ).

Here the example:
Code:
 
action mainplayer() // this is the action you're calling the function from
{
// your code
attackit(); // call the function out of the while loop
while (player != null)
{
// your code
wait(1);
}
}

function attackit
{
proc_kill(4); // makes sure that only one instance of this function running so proc_status isn't needed here ^^
ani_attack1_speed = 8;
ani_attack2_speed = 8;
while(player != null)
{
randomize();
my.attack_choose = int(random(2));
if(mouse_left && my.attack_choose == 0)
{
while (ani_attack1 < 100) // Solange ani....
{
ani_attack1 += (ani_attack_speed * time_step)%100; // Ani Speed
ent_animate(my, "attack", ani_attack1, 0); // Ani Bfehl
wait(1);
}
ani_attack1 = 0;
}
if(mouse_left && my.attack_choose == 1)
{
while (ani_attack2 < 100) // Solange ani....
{
ani_attack2 += (ani_attack2_speed * time_step)%100; // Ani Speed
ent_animate(my, "attack2", ani_attack2, 0); // Ani Bfehl
wait(1);
}
ani_attack2 = 0;
}
wait(1);
}
}



This is another approach but basically this should work and the animations should run properly

Cheers

Frazzle
Posted By: Moerk

Re: Animation in While! - 12/27/07 16:22

Thanks frazzle i found another solution to bring it to work.

Now i got a new big problem -.- Sorry for that guys!

Code:
function attackit
{
ani_attack1 = 0;
anilauft = 0;
//randomize();
my.attack_choose = 0;
while(anilauft != 1)
{
if(my.attack_choose == 0)
{
ent_animate(my,NULL,0,0);
ani_attack1 += (8 * time_step)%100; // Ani Speed
ent_animate(my, "attack", ani_attack1,anm_cycle+anm_add); // Ani Bfehl
if(ani_attack1 >= 100)
{
ent_animate(my,NULL,0,0);
ani_attack1 = 0;
anilauft = 1;
}
}
wait(1);
}
}

////////////////Action///////////////
action Player_Function
{
...
while(1) // Lebensenergie_Player > 0
{

//Tastatureingabe
Tastatur.x = (key_w - key_s);
Tastatur.y = (key_a - key_d);

//Animation
if(abs(Tastatur.x) == 0 && abs(Tastatur.y) == 0 && abs(Tastatur.z) == 0)
{
ani_stand = (ani_stand + 1*time_step)%100;
ent_animate(my,"stand",ani_stand,anm_cycle);
}
if(abs(Tastatur.x) == 1)
{
ani_walk = (ani_walk + Tastatur.x*time_step*6)%100;
ent_animate(my,"walk",ani_walk,anm_cycle);
}
if(mouse_left && proc_status(attackit) == 0)
{
attackit();
}



I forgot to say that i´m using bones and i think also a vertex animation ^^

The "walk" and "stand" animation works fine. I want to add the "attack" animation with "anm_add". The Problem is it doesn´t work. If i click on my left mouse button nothing happens. Only the walk or stand animation works but the attack animation don´t work. If i jump or walk left or right i didn´t create an animation yet. In this moment the attack animation works fine.

Why isn´t it working in combination with the animation and why is it working without animation?

Please help i´m going to kill myself!! Oo
Posted By: frazzle

Re: Animation in While! - 12/27/07 17:53

Killing youself will not bring the answer
But I find it wierd that you use anm_cycle and anm_add in combination but I'm guessing that there must be better methodes for blending animations. Try searching for this on the forum, I think DavidLancaster has made a great way of blending animations
Btw, why combining bone and vertex animations ??

Thanks in progress

Frazzle
Posted By: Moerk

Re: Animation in While! - 12/27/07 18:05

Ok it seems that it won´t work. I give up and search for a model without bones

Thanks for all!

Greetz!
Posted By: frazzle

Re: Animation in While! - 12/27/07 22:30

Vertex animations through code is also abit easier as handling bone animations through code. So logic, the blending part would be more complex when using bones But whereas the animations itself can be created more smoothly via bones than doing it the vertex way. Thus the more complex animations are handled via bones. I hope you find your model, turbo squid has got some fine models which are available for free

http://www.turbosquid.com/

Cheers

Frazzle
© 2024 lite-C Forums