|
Attaching weapons to the players hand
#383646
09/23/11 06:48
09/23/11 06:48
|
chris_oat
Unregistered
|
chris_oat
Unregistered
|
Guys, i need your help/opinion! im working on a 3rd Person game, and currently im busy with the weapon code. Everything work fine and i can figure most things out by myself but there is this one problem. Best way to attach the weapon(s) to the players hand? 1. MethodAttach the gun with vec_for_bone/vertex.
...
while(1)
{
vec_for_vertex (my.skill1, you, 999);
vec_for_vertex (my.skill4, you, 1000);
vec_diff (my.skill7, my.skill4, my.skill1);
vec_to_angle (my.pan, my.skill7);
vec_set (my.x, my.skill1);
wait (1);
}
...
Here i have the problem that when i shoot or aim (raising the gun for about 90 degrees) the gun suddenly turns around in the players hand. it returns to its position again when the gun is lowered and so on... Any idea on that? 2. MethodAnimate the gun together with the player. then delete the player mesh and save the gun with the animations and do it like this:
...
while(1)
{
//vec_set stuff here
my.frame = player.frame;
my.next_frame = player.next_frame;
wait(1);
}
...
This way seems almost perfect, as i dont need to worry about "gun turning"-problems  only downside i notice is that the gun model is too big in size because of the animations. Then i found "ent_animatefrom" which would be cool but i have no idea if and how i can combine 2. Method with "ent_animatefrom". I mean i think its possible to write its own animate_function for the guns just like for the player and only use instead of ent_animate - ent_animatefrom, but it would be better if there is a easier way. so now my questions: Which method would you prefer? Which is the most common, most efficient one? Can someone solve atlease one of the problems above?! Any input helps me! Thanks guys!
Last edited by chris_oat; 09/23/11 12:14.
|
|
|
Re: Attaching weapons to the players hand
[Re: ]
#383666
09/23/11 12:39
09/23/11 12:39
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
I would use Method 1 as I would not have to animate every gun model. The problem you've encountered is, of course, the vec_to_angle command. As it converts the directional vector into Euler angles and those angles are not unique, you experience that "weird" behaviour. You need to use a third vertex and set the gun model's roll value manually so (f.i.) the gun's left side always faces the third vertex. Have a look here Gimbal Lock, too.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: Attaching weapons to the players hand
[Re: Superku]
#385234
10/15/11 03:04
10/15/11 03:04
|
Joined: May 2010
Posts: 23
Mandeville
Newbie
|
Newbie
Joined: May 2010
Posts: 23
|
When attach the gun to the player's hand, it work. The problem is I cant move when i try to walk tothe right, where the gun is. There is the action script ;
action gun() {
set(my,PASSABLE); while(1) { vec_for_vertex (my.skill1, you, 244);
vec_diff (NULL, my.skill1, my.skill1); vec_to_angle (my.pan, my.skill1); vec_set (my.x, my.skill1);
my.pan=your.pan;
wait(1);
}
and there is the hole script;
///////////////////////////////
#include <acknex.h> #include <default.c> #define CREATOR skill1
#define ANIMATION skill2 #define STATE skill3
///////////////////////////////
function main() { video_screen = 7; screen_size.x = 1600; screen_size.y = 900; level_load("shooter.wmb");
}
function camera_follow(ENTITY* ent) { while(1) {
vec_set(camera.x,vector(camera.tilt-100,10,28)); vec_rotate(camera.x,ent.pan); // rotate the camera position with the player vec_add(camera.x,ent.x); //camera.y +=NULL ; camera.pan =ent.pan; //camera.tilt += ent.tilt;
camera.tilt += ( mouse_force.y) ;
wait(1); } }
action gun() {
set(my,PASSABLE); while(1) { vec_for_vertex (my.skill1, you, 244);
vec_diff (NULL, my.skill1, my.skill1); vec_to_angle (my.pan, my.skill1); vec_set (my.x, my.skill1);
my.pan=your.pan;
wait(1); }
} action man_walk() { camera_follow(me);
my.emask |= ENABLE_IMPACT;
VECTOR vFeet; vec_for_min(vFeet,me); // vFeet.z = distance from player origin to lowest vertex
// set FLAG2 to make the wizard detectable by c_scan, // and store the wizard pointer in its own CREATOR skill // in case the wizard is detected directly set(my,FLAG2); my.CREATOR = me;
my.STATE = 1; while (1) { // state 1: walking //////////////////////////////////////////// if (my.STATE == 1) { // rotate the entity with the arrow keys my.pan -= (mouse_force.x)*5*time_step; // my.tilt += mouse_force.y;
// move the entity forward/backward with the arrow keys var distance = (key_w-key_s)*5*time_step; c_move(me, vector(distance,0,0), NULL, GLIDE); var distance2= (key_a-key_d)*5*time_step; c_move(me, vector(0,distance2,0), NULL, GLIDE); // animate the entity my.ANIMATION += 2*distance; ent_animate(me,"walk",my.ANIMATION,ANM_CYCLE);
// adjust entity to the ground height, using a downwards trace c_trace(my.x,vector(my.x,my.y,my.z-1000),IGNORE_ME | IGNORE_PASSABLE); my.z = hit.z - vFeet.z; // always place player's feet on the ground
if (key_space) { // key pressed -> go to state 2 my.ANIMATION = 0; my.STATE = 2; } } // state 2: casting a spell /////////////////////////////////// if (my.STATE == 2) {
my.ANIMATION += 8*time_step; ent_animate(me,"attack",my.ANIMATION,0); if (my.ANIMATION > 100) { // create the spell and go to state 3
ent_create("pistol.mdl",vector(my.x,my.y,my.z),gun );
my.STATE = 1; } } // state 3: waiting for key release /////////////////////////// if (my.STATE == 3) { if (!key_space) my.STATE = 1; // when key was released, back to state 1 }
wait(1); } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// By the way, I based this on the litec workshop 24 and I use the A7 version.
Can you help me please?
|
|
|
Re: Attaching weapons to the players hand
[Re: Mandeville]
#385245
10/15/11 09:54
10/15/11 09:54
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
change
c_move(me, vector(distance,0,0), NULL, GLIDE);
to
c_move(me, vector(distance,0,0), NULL, GLIDE | IGNORE_PASSABLE);
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|