|
|
Attaching using vertex positions
#124724
04/18/07 01:38
04/18/07 01:38
|
Joined: Aug 2006
Posts: 18
diehard_101
OP
Newbie
|
OP
Newbie
Joined: Aug 2006
Posts: 18
|
Here's the code I'm using:
var hand_pos[3] = 0,0,0;
function vertex_attach { my.passable = on; while(you){ // weapon will always "face" the second vertice vec_for_vertex(my.x,you,12); //vertice at "pinky" side of palm vec_for_vertex(hand_pos.x,you,10); //vertice between thumb and pointer finger temp.x = hand_pos.x - MY.X; temp.y = hand_pos.y - MY.Y; temp.z = hand_pos.z - MY.Z; result = vec_to_angle(my_angle,temp); my.pan = my_angle.pan; my.tilt = my_angle.tilt; my.roll = my_angle.roll; wait(1);} }
I refined the code to look like this:
function vertex_attach { my.passable = on; while(you){ // weapon will always "face" the second vertice vec_for_vertex(my.x,you,12); //vertice at "pinky" side of palm vec_for_vertex(hand_pos.x,you,10); //vertice between thumb and pointer finger vec_sub(hand_pos.x,my.x); vec_to_angle(my_angle,hand_pos.x); vec_set(my.pan,my_angle); wait(1);} }
here's my problem: Everything works fine until the object attached to the entity rotates 90 degrees. then it flips to face the opposite direction and returns to its original position after the angle is passed.
Ex. A shield attached to an entity. When the players arm it is attached to extends to a 90 degree angle from the player the shield is also at the same angle and that is when it spins to face the opposite direction. Can someone run this little bit of code and try to give me some input. My brain must be to overwhelmed to think straight. thanks
UPDATE!
I correct my self -- the change only happens when the attached entity face directly up or down. --???
Last edited by diehard_101; 04/18/07 02:42.
|
|
|
Re: Attaching using vertex positions
[Re: diehard_101]
#124727
04/18/07 21:25
04/18/07 21:25
|
Joined: Aug 2006
Posts: 18
diehard_101
OP
Newbie
|
OP
Newbie
Joined: Aug 2006
Posts: 18
|
ok I tried the c_rotate but all it did was continuously rotate the objects. Maybe I was typing it wrong I dont know. Never used it before. I decided to include a little illustration to help picture whats going on. www.geocities.com/diehard_101/illu1.jpgIn the first shot the characters arm is forward and the shield follows prefectly. In the second shot the arm is back and as you can see the shield has done a 180. I'm lost. If anyone can fix this bit of code much credit will be given.
|
|
|
Re: Attaching using vertex positions
[Re: diehard_101]
#124728
04/19/07 02:18
04/19/07 02:18
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
It should be fine, unless the vertices are moving incorrectly. Check your animations to make sure that the vertices aren't too close and do not "flip" for any reason.
xXxGuitar511 - Programmer
|
|
|
Re: Attaching using vertex positions
[Re: diehard_101]
#124730
04/19/07 05:31
04/19/07 05:31
|
Joined: Apr 2004
Posts: 516 USA
Trooper119
User
|
User
Joined: Apr 2004
Posts: 516
USA
|
Alright, I think I found out your solution, but its in the works, I remembered the "office" level has a patroling guard in it with an attached shield and spear, so I found its code. As you can see, the highlighted area (red) gives the ability to correctly attach an object to a vertex, i'm currently looking for this stupid function, its not in the same office level code. Code:
action patrol_prog { guard = me; // watched = me;
// first, set the entity properties my.fat = off; my.narrow = on; my._walkframes = 1; my._movemode = _mode_walking; my._force = 1.5;
// then, call all standard tasks the entity shall perform patrol_path(); if (my.shadow == off) { drop_shadow(); }
// add an event: touching it with the mouse my.string1 = "walking\nguard"; my.enable_touch = on; my.event = handle_touch;
// my.enable_click = on; // my.event = _save;
// attach other entities - AFTER setting the patrol movement action ent_create(shield_mdl,nullvector,attach_entity); ent_create(mace_mdl,nullvector,attach_entity);
// a non-standard entity function - like disappering // on pressing the [R] key - may be directly scripted here, like this: while (1) { if (KEY_R) { remove(ME); } wait(1); } }
I'll make a new post when I find the right code, but you may be able to bypass this whole piece of code if you subsitute(sp sorry) you current code with an ent_create(NAME_OF_ENTITY, Nullvector, attach_entity); and then simply include wherever this attach_entity's code with it, like I said, I'm looking. Then again, once I find it you can modify the code to your liking.
A clever person solves a problem. A wise person avoids it. --Einstein
Currently Codeing: Free Lite-C
|
|
|
Re: Attaching using vertex positions
[Re: Trooper119]
#124731
04/19/07 05:41
04/19/07 05:41
|
Joined: Apr 2004
Posts: 516 USA
Trooper119
User
|
User
Joined: Apr 2004
Posts: 516
USA
|
Alright, I think we are finished, I found the piece of code in animate.wdl (For fair warning, I have A5, so an updated piece of code may be present in A6 versions). Here is the code inside animate.wdl: Code:
///////////////////////////////////////////////////////////////////////// // Desc: attaches an entity that has the same origin and the same frame cycles // function attach_entity() { my.passable = on; while(you) // prevent empty synoym error if parent entity was removed { if(your.shadow == on) { my.shadow = on; } if(you == player && person_3rd == 0) { my.invisible = on; } else { my.invisible = off; } vec_set(my.x,you.x); vec_set(my.pan,you.pan); my.frame = you.frame; my.next_frame = you.next_frame;
wait(1); } remove(my); }
The highlighted code is what you seem to need, but I REALLY don't understand how it gets the proper vertex number or what this my.frame or my.next_frame is, have to look it up in the manual I guess, I hope this helps, if it doesn't let me know, I'll disect some code some more.
Last edited by Trooper119; 04/19/07 05:42.
A clever person solves a problem. A wise person avoids it. --Einstein
Currently Codeing: Free Lite-C
|
|
|
Re: Attaching using vertex positions
[Re: Trooper119]
#124732
04/19/07 12:46
04/19/07 12:46
|
Joined: Aug 2006
Posts: 18
diehard_101
OP
Newbie
|
OP
Newbie
Joined: Aug 2006
Posts: 18
|
That doesn't attach the entity to a vertex. The weapons in the office tutor are animated with the same frames as the character. Thats how its being animated. They are just matching the weapons frame to the entity thats holding its frame. my.frame = you.frame(My the attached entity - You the entity being attached to) The next_frame is used so that the frame of the weapon can be smoothly "looped" back to the first frame in the animation cycle at the same time as the character. interpolation I think its called. That way when it reaches the last frame in the cycle it doesn't just poof back into the first frame. I'm going to have a LOT of weapons/items in the game I'm building and just about every character in the game can hold any one of the weapons/items. That would be a lot of animating. To much for one person to complete in a respectable amount of time. Thats why I chose to attach the weapon/item to any vertex on any entity. Then it moves with the entities arm, shoulder, head, leg, etc... with out me having to make frames that match whatever entity it is attached to. I refuse to believe the little bug in the code I posted at the top cannot be fixed. It has something to do with the position of HAND_POS and MY. Imagine drawing a straight line from your shoulder to your elbow. Your shoulder will be MY Your elbow will be HAND_POS Now as you walk your elbow will swing infront of your shoulder then be behind it. Now your shield is attached to that part of your arm. As your elbow moves back and passes your shoulder the line(from your shoulder to your elbow) is a straing line running down. Your shield is also facing down. The shield now flips so that the back of the shield is facing out and the front is facing you. It keeps this orientation as your arm swing back until that point is reached again as the arm swing back to the front. When it passes the same point headed to the front the shield swings back around to face the correct direction. This repeats with every swing of the arm. I thought it might have something do to with when the attached entity passed the model center. but nope. Has nothing to do with that. Its something that has to be taken into account when you use -vec_sub(hand_pos.x,my.x);- Who out there can help!? 
|
|
|
|