Game Development Community

Platform tut

by Anthony Ratcliffe · in Torque Game Builder · 06/22/2008 (6:13 am) · 5 replies

Just reading through the tutorial for refrence and also looking at the game icewolf in show off. I have a question regarding the player animations ect. I'd like to add a new function to it saying if button pressed do this animation

couldnt find much info on it so i'd like to ask if this is roughly right

moveMap.bindCmd(keyboard, "Z", "playerattack();", "");         // this defined at top with other keys






function playerhit()
{
    $player.hit = true;                // sets player hit to true
}


if ($player.hit == true)          // when player hit equal to true play below animation
{
%this.playAnimation(PlayerhitAnimation);
return;
}

#1
06/23/2008 (12:05 am)
Well, other than ending your function prematurely. And if that is the case setting it to true and immediately checking if it is true after that is kinda' pointless. Try something like...
moveMap.bindCmd(keyboard, "Z", playerattack();", "");



function playerhit()
{
    $player.playAnimation(PlayerhitAnimation);
    //I suppose you could also cast a collision check here to 
    //  see if the player is hitting something.
}

This works fine if you want to just run the animation once. If you want the player to continuously attack you might want to check into using the same method as the tutorial does to play the animation on updates.
#2
06/23/2008 (7:49 pm)
Haha, this is one the first code I did when I bought TGB and learned scripting, 2 years ago.
Basically, you make a function (called animate or whatever), that will check a bunch of condition about the state of your player/npc, then make it play the right animation.

function player::animate(%this)
{
	if(player.hit)	
	player.setanimation("playerhit");
	else if(player.goleft)
	player.setanimation("playerleft");
	else if(player.goright)
	player.setanimation("playerright");
	else if .... etc
}
This way, you'll have a good easy way to order your animations in a hierarchical way. Everytime you think the animation could change (when pressing a button or when being hit by a projectile), you'll simply have to call "player.animate()", and it will see what is the right animation to play.

It really helps when your game gets complicated, when many states and button presses or other events can overlap.
#3
06/24/2008 (5:42 am)
Dan dias

just wondering if theres a mistake you called playerattack with the z key but the function is playerhit just to comfirm shouldnt they both me the same name? havent tried it yet just wanted a quick run through before i do
#4
06/24/2008 (9:26 am)
Anthony,

Yes it should be playerattack. I was actually just following your skeleton exactly. You may also consider Benjamin's suggestion of using a "catch all" animation function (which is similar to how the tutorial does it I believe.) Good luck!
#5
06/24/2008 (2:25 pm)
Thank you for your help