Animation Blues
by Damian Sloane · in Torque Game Engine · 03/14/2007 (3:00 am) · 1 replies
I've been using the "tutorial.base" as the starting point for my project, I've stripped everything down to the absolute bare-bones just the way I want it- except the player model/animations.
Here's the default datablock from "player.cs"
I've got a nice new shiny model all rigged up, DSQ files intact, nice new datablock setup as below.
This all shows up and animates perfectly in ShowTool Pro.
The problems all start because the player initally falls out of the sky and lands on the ground, so it wants to play the "land" animiation. But lets say I don't want a land animation- what then? I've looked in the engine code and found hard-coded references to various animations.
For simplicity lets say I was writing a *very* simple version of "Marble Blast" (I'm actually writing yet another mech combat game, feel free to groan). But thinking simple, my player is nothing more than a sphere that has a single root animation (eg. sitting still doing nothing).
Do I have to start modifying the engine code in player.cc/player.h to do this?
Are all of these animations (land, jump, run, back, side, etc) hard-coded into the engine?
I would be hoping most of this could just be controlled in scripts with a "setAnimation" type function, (eg. If player hits walk forward key, start the walk animation- if the player lets go of the key, stop it). I can *kind* of understand why some of the "triggered" animations that arent initiated by direct user input could be in the engine code, but things that are clearly initiated by user input defined in scripts seems like it shouldnt be hard-coded (happy to be proven wrong). I've seen people on the forums ending up with code looking like this:
Just to "fill in the blanks", and I admit I could very easily just stick a blank "land" animation where the engine expects it and stop my game crashing, but its hacky and I'd rather not start bad habits.
HELP!
Here's the default datablock from "player.cs"
datablock TSShapeConstructor(PlayerDts)
{
baseShape = "~/data/shapes/player/player.dts";
sequence0 = "~/data/shapes/player/player_root.dsq root";
sequence1 = "~/data/shapes/player/player_forward.dsq run";
sequence2 = "~/data/shapes/player/player_back.dsq back";
sequence3 = "~/data/shapes/player/player_side.dsq side";
sequence4 = "~/data/shapes/player/player_fall.dsq fall";
...
};I've got a nice new shiny model all rigged up, DSQ files intact, nice new datablock setup as below.
datablock TSShapeConstructor(mech02Dts)
{
baseShape = "./mech02.dts";
sequence0 = "./mech02_walk.dsq Walk";
sequence1 = "./mech02_run.dsq Run";
sequence2 = "./mech02_walkback.dsq Walkback";
sequence3 = "./mech02_shootwalk.dsq Shootwalk";
sequence4 = "./mech02_shoot01.dsq Shoot01";
sequence5 = "./mech02_shoot02.dsq Shoot02";
sequence6 = "./mech02_shoot02loop.dsq Shoot02loop";
sequence7 = "./mech02_gethit01.dsq Gethit01";
...
};This all shows up and animates perfectly in ShowTool Pro.
The problems all start because the player initally falls out of the sky and lands on the ground, so it wants to play the "land" animiation. But lets say I don't want a land animation- what then? I've looked in the engine code and found hard-coded references to various animations.
// *** WARNING ***
// This array is indexed useing the enum values defined in player.h
// Root is the default animation
{ "root" }, // RootAnim,
// These are selected in the move state based on velocity
{ "run", { 0,+1,0 } }, // RunForwardAnim,
{ "back", { 0,-1,0 } }, // BackBackwardAnim
{ "side", { -1,0,0 } }, // SideLeftAnim,
// These are set explicitly based on player actions
{ "fall" }, // FallAnim
{ "jump" }, // JumpAnim
{ "standjump" }, // StandJumpAnim
{ "land" }, // LandAnimFor simplicity lets say I was writing a *very* simple version of "Marble Blast" (I'm actually writing yet another mech combat game, feel free to groan). But thinking simple, my player is nothing more than a sphere that has a single root animation (eg. sitting still doing nothing).
Do I have to start modifying the engine code in player.cc/player.h to do this?
Are all of these animations (land, jump, run, back, side, etc) hard-coded into the engine?
I would be hoping most of this could just be controlled in scripts with a "setAnimation" type function, (eg. If player hits walk forward key, start the walk animation- if the player lets go of the key, stop it). I can *kind* of understand why some of the "triggered" animations that arent initiated by direct user input could be in the engine code, but things that are clearly initiated by user input defined in scripts seems like it shouldnt be hard-coded (happy to be proven wrong). I've seen people on the forums ending up with code looking like this:
sequence2 = "~/data/shapes/player/die.dsq death2"; sequence3 = "~/data/shapes/player/die.dsq death3"; sequence4 = "~/data/shapes/player/die.dsq death4"; sequence5 = "~/data/shapes/player/die.dsq death5"; ...
Just to "fill in the blanks", and I admit I could very easily just stick a blank "land" animation where the engine expects it and stop my game crashing, but its hacky and I'd rather not start bad habits.
HELP!
About the author
Torque 3D Owner Tony Richards
Absolutely... Player.cc / Player.h (and yes, even ShapeBase.*) should be used as "sample code" and you should modify them to suit your needs.