|
Rotating a model with bones
#202614
04/16/08 02:24
04/16/08 02:24
|
Joined: Mar 2008
Posts: 67
crumply
OP
Junior Member
|
OP
Junior Member
Joined: Mar 2008
Posts: 67
|
Hello, I am writing a walking mech game. This involves using a model with bones. If I try to alter the pan in-game the mesh distorts. Does this mean I have to use ent_bonerotate on the parent of the bones to rotate the model or is something terribly wrong? -Ed http://indiegamingportal.net/uploads/screenshots/2008-04-16_032401.jpgHere is my code: #include <acknex.h>
#include <default.c>
VECTOR vSpeed, vAngularSpeed, vForce, vMove, vKick, velocity, vec;
var walk_speed, cabin_rotate, gun_rotate;
action mech()
{
set(my,SHADOW);
my.material = mat_metal;
camera.y = my.y - 50*sin(my.pan);
camera.x = my.x - 50*cos(my.pan);
camera.z = my.z + 230;
camera.tilt = -10;
camera.pan = my.pan-180;
while(1)
{
ent_animate(my, NULL, 0, 0); // reset all the animations
walk_speed += 4 * time_step; // increase walk_speed; 1.5 sets the speed
gun_rotate -= mouse_force.y;
cabin_rotate -= mouse_force.x;
if (key_w){
ent_animate(my, "walk", walk_speed, ANM_CYCLE);
c_move(me,vector(-3*time_step,0,0),nullvector,IGNORE_YOU|GLIDE);
my.pan += 2;
}
ent_bonerotate(my,"railgun",vector(0,gun_rotate,0 ));
ent_bonerotate(my,"cabin",vector(cabin_rotate,0, 0));
if(!c_trace (my.x,vector(0,0,-1),IGNORE_ME|IGNORE_PASSABLE)){
c_move(me,vector(0,0,-30*time_step),nullvector,IGNORE_YOU|GLIDE);
}
wait(1);
}
}
function main()
{
level_load("terrain_desert.hmp");
//shadow_stencil = 1;
wait(3);
ph_setgravity(vector(0,0,-386));
ent_create("mech_walk.mdl",vector(0,0,200),mech);
}
Last edited by crumply; 04/16/08 02:25.
|
|
|
Re: Rotating a model with bones
[Re: crumply]
#202615
04/16/08 02:32
04/16/08 02:32
|
Joined: Apr 2004
Posts: 516 USA
Trooper119
User
|
User
Joined: Apr 2004
Posts: 516
USA
|
There was a really kick ass example in A7's templates, let me dig it up for you. Give me a sec..... Found it, it was Workshop 23, Workshop 22 has a non-bone version, this one takes the screen coordinates of the mouse, and blends that position with the turrets normal animation with walking to get a good effect. You can use this as a jump board to get what you want. (take a look in your lite-c/workshops folder to find workshop 23 to take a closer look) /////////////////////////////// #include <acknex.h> #include <default.c>
///////////////////////////////
var walk_speed; // stores robot's walking speed ANGLE bone_angle; // a vector that holds the pan, tilt and roll angles BMAP* crosshair_pcx = "crosshair.pcx"; // the bitmap used for our crosshair
////////////////////////////////////////////////////////////////////////////////////
function rotate_bone() { my.pan = -180; // face the camera while(1) { walk_speed += 2 * time_step; // increase walk_speed, "2" sets the animation speed ent_animate(my, "walk", walk_speed, ANM_CYCLE); // animate the model (use "walk") bone_angle.pan = (mouse_pos.x - screen_size.x / 2) / 10; // changes pan from -40 to +40 degrees bone_angle.tilt = (screen_size.y / 2 - mouse_pos.y) / 10; // changes tilt from -30 to +30 degrees bone_angle.roll = 0; // no need to change the roll angle for this bone ent_bonereset(my,"CA4"); ent_bonerotate(my,"CA4", bone_angle); // rotate the bone named "CA4" wait(1); } }
function main() { video_mode = 7; // set the screen resolution to 800 x 600 pixels level_load (""); // load an empty level wait(2); // wait until the level is loaded ent_create("robot.mdl", vector(400, 0, -50), rotate_bone); // and then create the robot model mouse_map = crosshair_pcx; // set the bitmap that is going to be used by the mouse pointer mouse_mode = 2; // now show the pointer while (1) { vec_set(mouse_pos, mouse_cursor); // update the mouse pointer position at all times wait (1); } }
Last edited by Trooper119; 04/16/08 02:38.
A clever person solves a problem. A wise person avoids it. --Einstein
Currently Codeing: Free Lite-C
|
|
|
|