Gamestudio Links
Zorro Links
Newest Posts
blogherenowcenter
by 3s05bmmc. 06/05/24 06:08
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 853 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19057 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
how can I use vec_length #113626
02/23/07 17:06
02/23/07 17:06
Joined: Jan 2007
Posts: 230
london uk/ paris
S
sueds Offline OP
Member
sueds  Offline OP
Member
S

Joined: Jan 2007
Posts: 230
london uk/ paris
I'm looking for some explanation about vec_length cause the manual is not than clear.

I try to make ma character react in a different way if the other character is benind him in the X axis but when I try with vec_length it doesn't work, the character didn't detec the instruction.

vec_length (play1.x);
vec_length(play2.x);


if (play1.x<play2.x)

{ ...

did i misunderstand the function of vec_length ? do you have some example ?
Do I've to try with c_trace?

Thanks for your help

Re: how can I use vec_length [Re: sueds] #113627
02/23/07 17:24
02/23/07 17:24
Joined: Mar 2006
Posts: 752
Portugal
demiGod Offline
User
demiGod  Offline
User

Joined: Mar 2006
Posts: 752
Portugal
The manual has an example:

distance = vec_length(my.x); // calculate the distance of the my entity to the level origin

So you need to save the magnitude of those vectores in a variable for example.
Also, if you want to have always a positive value to evaluate, take a look at abs() command which returns an absolute value.

Re: how can I use vec_length [Re: demiGod] #113628
02/23/07 19:42
02/23/07 19:42
Joined: Jan 2007
Posts: 230
london uk/ paris
S
sueds Offline OP
Member
sueds  Offline OP
Member
S

Joined: Jan 2007
Posts: 230
london uk/ paris
So when you said the distance is not for example
my entity = -30

it's the distance between the origin and the entity is 30 ?

so with vec_length I can't compare two position on the X axis ? like
if my.entity.x < your.entity.x

I tried with abs but it didn't work.

cheers

Re: how can I use vec_length [Re: sueds] #113629
02/23/07 19:45
02/23/07 19:45
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
If you only want to compare positions on the X axis for some reason, then it's just (my.x < your.x). You don't need vectors for that.

Re: how can I use vec_length [Re: jcl] #113630
02/23/07 20:27
02/23/07 20:27
Joined: Jan 2007
Posts: 230
london uk/ paris
S
sueds Offline OP
Member
sueds  Offline OP
Member
S

Joined: Jan 2007
Posts: 230
london uk/ paris
I did use to compare 2 x position with

play1 and play2

My.x and your.x was an example, the engine says there is an empy pointer even if I define play2= you

is it cause they are two entity controlled by different players ?

Re: how can I use vec_length [Re: sueds] #113631
02/23/07 21:09
02/23/07 21:09
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
It shouldn't be a problem to have two entities controlled by different players.

Here is an example code that should work (e.g. for a splitscreen game):
Code:

entity* player1;
entity* player2;

action player1_act
{
player1 = my;
//here comes the rest of your movement code for player 1
}

action player2_act
{
player2 = my;
//here comes the rest of your movement code for player2
}



Now you should be able to get the x-distance between both of them and store it into a var:
Code:

var distance;

//put this into a function:
distance = abs(player1.x - player2.x);



But you have to make sure that both entities exists and that their pointers are not zero.

Re: how can I use vec_length [Re: Xarthor] #113632
02/23/07 21:09
02/23/07 21:09
Joined: Mar 2006
Posts: 752
Portugal
demiGod Offline
User
demiGod  Offline
User

Joined: Mar 2006
Posts: 752
Portugal
Big confusion around here.

Like jcl said, if you only want to compare two positions along the x axis it very simple:



You need to have the pointers defined for the two entities, so:

if(entity1.x < entity2.x) //entity1 behind entity2
{
...
}

I cant see where is the problem here.

You can do that with vectors too but this way its simpler.

Edit: Thunder was faster

Last edited by demiGod; 02/23/07 21:10.
Re: how can I use vec_length [Re: demiGod] #113633
02/23/07 22:39
02/23/07 22:39
Joined: Jan 2007
Posts: 230
london uk/ paris
S
sueds Offline OP
Member
sueds  Offline OP
Member
S

Joined: Jan 2007
Posts: 230
london uk/ paris
you're both right but in fact it doesn't work and I don't know why

My code is a bit complicated so to avoid error I've made one simplier to see is the program could make a simple action like if (entity.1<entity.2)
{Z+=5;}

but It didn't work when I change entity's position

maybe I need to update them, it's the reason i've decided to use vec but I didn't find the way to get the update


this is the simple code


action play1

{
while(1)
{
p1= me;
my.x+=2*key_force.x*time;
if (p1.x>p2.x)
{
my.z+=5*time;
}
wait(1);

}
}

action play2{

while(1)
{
p2=me;
my.x+=2*joy_force.x*time;wait(1);
}


}

Re: how can I use vec_length [Re: sueds] #113634
02/23/07 23:37
02/23/07 23:37
Joined: Mar 2006
Posts: 752
Portugal
demiGod Offline
User
demiGod  Offline
User

Joined: Mar 2006
Posts: 752
Portugal
1. Do not assign the pointers in the while loop, just put it in begin of the action:

Code:


entity* p1;
entity* p2;

action play1
{
p1 = my;
while(p2==null){wait(1);}
while(1)
{
my.x += 2 * key_force.x * time;
if (my.x > p2.x)
{
my.z += 5 * time;
}
wait(1);
}
}

action play2
{
p2 = my;
while(1)
{
my.x += 2 * joy_force.x * time;
wait(1);
}
}




This should work. Dont forget you need to move p1 to a point where its x is superior do p2, otherwise it wont work.


Moderated by  old_bill, Tobias 

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