Gamestudio Links
Zorro Links
Newest Posts
Z9 getting Error 058
by jcl. 04/24/26 17:48
ZorroGPT
by TipmyPip. 04/23/26 14:23
Stooq now requires an API key
by jcl. 04/13/26 09:42
Strange "Alien" Skull created with >Knubber<
by NeoDumont. 04/10/26 18:58
400 free seamless texture pack downl. here !
by NeoDumont. 04/08/26 19:55
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
0 registered members (), 3,176 guests, and 11 spiders.
Key: Admin, Global Mod, Mod
Newest Members
valino, juergenwue, VladMak, Geir, ondrej
19209 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
easy...but not for me #164399
10/30/07 13:19
10/30/07 13:19
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
Hello

I know I'm a prick...but can somebody help me with this (it takes too long for me to translate into c-script ) :

I have a river and would like to calculate the stream-force direction according to the rivers vertices (the vertices are setup like 1,3,5,7,9...). Now when my boat is at vertex#1 position, the stream-force direction should point towards vertex#3 position...and so on.

I'd be very glad for a snippet that manages this

Thanks!

Re: easy...but not for me [Re: Loopix] #164400
10/30/07 13:31
10/30/07 13:31
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
ok, here's an idea...

If it indeed is all in the correct order (1-2, 3-4, 5-6, 7-8 etc etc), you could calculate the distance and rotation.

first you set a temp variable at the current vertex.
then you calculate the distance from the boat to the next vertex, and check if that distance is shorter then the current one, if so, the next is the current one.

then you can use the current and next one to calculate a rotation angle.
after doing that, you can also speed up / slow down the boat using the distance between these 2 vertices...

i am at work atm, cant test/write any code, but it's a general idea.
I'll check later what i can do, can you upload the river model somewhere?

regards,


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
Re: easy...but not for me [Re: Helghast] #164401
10/30/07 13:40
10/30/07 13:40
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
Hey thanks for your fast input...your idea sounds cool!

Here's the river model

Re: easy...but not for me [Re: Loopix] #164402
10/31/07 09:22
10/31/07 09:22
Joined: Jan 2007
Posts: 221
F
Fenriswolf Offline
Member
Fenriswolf  Offline
Member
F

Joined: Jan 2007
Posts: 221
Hi,

you can use c_trace to get the closest vertex to your boat. 'hitvertex' will be set to its number.

Then you could determine if the vertex number is even or uneven to get the correct vertex pair. However you only need this, if the broadness of your river varies. In this case you need to get a direction vector from one vertex pair to the following vertex pair. A 'vertex-to-vertex' direction vector could result in a inapplicable direction.

You can determine if a number is even by using something like the following function:

function even(_n) {
// returns 1 if _n is even, otherwise 0
return(_n % 2 == 0);
}

To get the direction vector from one pair to the next pair you would have something like this:

------
// get the position of the closest vertex pair

vec_for_vertex(temp, river, closest_vertex); // get the vector of the closest vertex
vec_for_vertex(temp2, river, closest_vertex - (2 * even(closest_vertex) - 1); // get the vector of the adjacent vertex

vec_add(temp, temp2);
vec_scale(temp, 0.5);
vec_set(pair1, temp); // pair1 = origin of the vertex pair

// get the position of the next vertex pair

vec_for_vertex(temp, river, closest_vertex + 2); // get the vector of the next vertex
vec_for_vertex(temp2, river, closest_vertex - (2 * even(closest_vertex + 2) - 1); // get the vector of the adjacent vertex

vec_add(temp, temp2);
vec_scale(temp, 0.5);
vec_set(pair2, temp); // pair2 = origin of the vertex pair

// finally get the direction vector

vec_diff(speed_vector, pair2, pair1);
------


This is a sloppy written code and I don't know if it actually works. ;-)

Re: easy...but not for me [Re: Fenriswolf] #164403
10/31/07 12:47
10/31/07 12:47
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
Thanks Fenriswolf! Sound usefull too. Is there a way to avoid the c_scan??

Re: easy...but not for me [Re: Loopix] #164404
10/31/07 15:04
10/31/07 15:04
Joined: Jan 2007
Posts: 221
F
Fenriswolf Offline
Member
Fenriswolf  Offline
Member
F

Joined: Jan 2007
Posts: 221
Instead of using c_trace you could also use vec_dist to calculate which is the closest vertex to your boat.

You can do this thusly:

------
var closest_vertex; // number of closest vertex
var closest_vertex_distance; // distance of closest vertex
var i;

i = ent_vertices(river_entity);
vertex_distance = 999999; // initializing with highest possible value

while(i > 0) {
vec_for_vertex(temp, river_entity, i);

var vertex_distance;
vertex_distance = vec_dist(boat_entity.x, temp);

if (vertex_distance < closest_vertex_distance) { // if this is the closest vertex, save it
closest_vertex_distance = vertex_distance;
closest_vertex = i;
}
i -= 1;
}

// at this point closest_vertex stores the number of the closest vertex to the boat
------

Of course you can put this code into a function to make it universally applicable.


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

Gamestudio download | 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