Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
3 registered members (TedMar, AndrewAMD, fairtrader), 578 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
Attaching using vertex positions #124724
04/18/07 01:38
04/18/07 01:38
Joined: Aug 2006
Posts: 18
D
diehard_101 Offline OP
Newbie
diehard_101  Offline OP
Newbie
D

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] #124725
04/18/07 10:42
04/18/07 10:42
Joined: Oct 2003
Posts: 702
Z
zazang Offline
User
zazang  Offline
User
Z

Joined: Oct 2003
Posts: 702
maybe you are facing a similar problem I faced :-

http://www.coniserver.net/ubbthreads/sho...true#Post520833


I like good 'views' because they have no 'strings' attached..
Re: Attaching using vertex positions [Re: zazang] #124726
04/18/07 10:52
04/18/07 10:52
Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
tompo Offline
User
tompo  Offline
User

Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
try to use c_rotate with USE_AXISR maode.


Never say never.
Re: Attaching using vertex positions [Re: diehard_101] #124727
04/18/07 21:25
04/18/07 21:25
Joined: Aug 2006
Posts: 18
D
diehard_101 Offline OP
Newbie
diehard_101  Offline OP
Newbie
D

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.jpg

In 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 Offline
Expert
xXxGuitar511  Offline
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: xXxGuitar511] #124729
04/19/07 03:21
04/19/07 03:21
Joined: Aug 2006
Posts: 18
D
diehard_101 Offline OP
Newbie
diehard_101  Offline OP
Newbie
D

Joined: Aug 2006
Posts: 18
I've checked my models all of the vertices stay in alignment. Also created a test model and placed the Vertices I was going to use far apart. Still the same result. I think I've narrowed it down to the vec_sub function. When the attached object pans to face the opposite direction the value of hand_pos minus my, flips it value so to speak. In other words the value goes from positive to negative or viceversa. This happens when either the x of the first vertex aligns with and then passes the position of the second x. The same goes for the y and z values. Could that little change affect the calculated angle for the object. If so then how can it be corrected?

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 Offline
User
Trooper119  Offline
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 Offline
User
Trooper119  Offline
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
D
diehard_101 Offline OP
Newbie
diehard_101  Offline OP
Newbie
D

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!?


Re: Attaching using vertex positions [Re: diehard_101] #124733
04/19/07 12:56
04/19/07 12:56
Joined: Aug 2006
Posts: 18
D
diehard_101 Offline OP
Newbie
diehard_101  Offline OP
Newbie
D

Joined: Aug 2006
Posts: 18
I just thought of something. I dont know if this will help someone to fix this but the samething happens when using a stationary camera. I'll explain.

Imagine having a camera in the center of a room attached to the ceiling. Now as your character runs directly underneath the camera its pan spins around so to keep up as up.

I believe the same thing is happening to the shield in my game.

The shield is attached to the first vertex at the shields center. It's then rotated to "face" the second vertex in the code. When it facing directly up or down it is doing the same thing as the camera. adjusting pan/tilt/roll to keep up as up. How to you tell it that it's ok if the shield is up side down. and prevent this from happening.

....

Page 1 of 3 1 2 3

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1