point_direction, point_distance, best way to find ?

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

point_direction, point_distance, best way to find ?

Post by jph_wacheski »

I love ZGE! the concept rules,. component based IDE, compileing tinny .exe files, using procedural methods to generate content, both audio and visual, just perfect!

point_direction and point_distance are two bits of information needed for most games I can think of creating,. while currently ZGE does not provide simple functions for finding this information scripting solutions must be found,.

so math-heads recall your basic 2d math? I suppose its Trig. we are lookng at,. some form of pythagorean theorem,. .

Coming from some years of dev.ing with GameMaker I am use to useing the functions Mark had supplied in the form; point_direction(x,y,x2,y2) giveing an angle in degrees,. given ZGE is a 3d system,. point_direction(x,y,z,x2,y2,z2) would be nice to know as well., and that brings me to a related point,.

closest and farthest are also very usefull functions assuming we get a way to address instances in ZGE at some point,. in GM these functions only return the closest or furthest and in my experiance a handy feature of these functions would be the inclusion of a distance number to allow for finding the Nth closest object,. . the form would be something like; instance_nearest(x,y,obj_type,n)

The inclusion of the four functions would allow for easy scripting of most imaginable game types and are espesially usefull for building behavoiurs and A.I.s. till then can anyone help me get the fastest math to find these values ?
Attachments
rotation_trust_02.zgeproj
here is sprite based example of where this is needed,. . I hacked some trig in and although the spiral effect is cool more hacking is needed. .,
(2.25 KiB) Downloaded 486 times
iterationGAMES.com
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi jph_wacheski,

While I have to vote against the 2D varieties of your suggestions as ZGE does not have a 2D system in place at all, I do agree that not being able to get the distance between 2 objects easily ( or anything regarding instances for that matter ) is quite a shortcoming.
Off-topic: The absence of a Raycast component with properties such as intersection position / normal / distance .. a even bigger one.
Going about finding the nearest / furthest object to a reference generally requires the ability to iterate through a list / array, which is not supported by the scripting language at the moment. The easiest alternative approach I can think of is to name each one of your instances individually, and write a ZExpression that calculates each of the Model's relative distance storing the case id of the Model with the highest / lowest result. This might be incredibly tedious though ..

And you are right, in order to calculate a distance in 3D you need some basic Trig Math :wink: First get the distance between the two points per axis and then use the following formula: sqrt(sqr(x)+sqr(y)+sqr(z));

Concerning your example, you need to calculate the X / Y translation values using sin(angle) / cos(angle). And when you want to do the opposite, namely; calculating a angle, use arctan2(y,x). I suggest you take a look at Ville's FPS example which uses such approach for the camera movement.

Good luck~
K
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

I've used a bit of GameMaker so I know about the runtime library routines and they would be very useful for ZGE also.
This is part of the big "rewrite scripting support" feature of ZGE so I cannot make any promises when it will appear.
Right now I believe what ZGE needs the most is more people using it. If there are more users then the possibility of me getting help with open source development increases. Also with more active users my own motivation will get a boost. If you can help spread the word about ZGE then please do so, thanks! :)
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

sin cos, 2d math,.and keeping positive focuss.

Post by jph_wacheski »

kjell - thanks for the pointers,. Ville's FPS example does show this, however its set up in the x and z axis, strange. I hacked in the sin/cos in and got the rotaional thrusting working,. I was perhaps trying to make it more complex than was actually needed,. I should have paid attention in math class,. eh.
I am not at all sure what you mean when you say "ZGE does not have a 2D system in place at all" ? ZGE is quite obsiously set up to make 2d games simple. Just use x,y and keep the camera above in z,. the way it's set by default. Having 0,0,0 be the center of the universe, also by default, is great and the auto-scaling of all things to have the games viewable under any rez. is also quite wise indeed. (major improvment from GM)
As far as the limitations of ZGE well they are what they are,. however, I find that many times people (myself included) get fixated on doing a thing the first way they think of it, instead of finding a way to do it within the limitations of the platform,. what I'm getting at here is that perhaps we should try to avoid bitching about what in not there and focuss on exploiting more FULLY what is! So far I am quite impressed with that can be achived in ZGE and I have not even begun to play with shaders and more complex rendering stuff, but I will!

Ville- I know it must be frustrating to have a bunch of people asking for all these features and no one actually offering to help build them! So far each time I have run up against a problem building something with ZGE the solution has been there, and I just needed to look at the idea from a slightly different angle,. thanks for all your help.
As far as getting more people involved,. I am willing to help with that,. first thing that comes to mind for me is perhaps I could offer myself as a moderator in the forum as when I first looked at ZGE that is where I went (even befor d/l the IDE!) just to see how much it could do,. and some of the posts are quite old refering to the lack of features that are now in ZGE,. keeping the forum neat and up to date will help new users learn. I am also thinking of writing some basic tutorials on the setting up stuff and getting basic things working as I know that is what helps me whith a new system,. something that works and can easily be deconstructed and re-perposed into a new design.
The biggest boost in users will come from haveing some killer games viraly spreading around the net,. perhaps we can get a logo for ZGE that game makers can volenterily add to their creations,. to get a sence of ZGE branding going,. and/or perhaps you could add a 'games links' page to site to add direct links to games that you think deserve it,. . I am always planing a 're-build' on my site, and when that actually happens I will add a link to your main ZGE site from there,. . peace
Attachments
rotation_trust_04.zgeproj
here is a basic game templet; features rotaional movement (astroids-ish) and shows how to pass values to objects when they are spawned (simple once seen) . This also shows how to set up sprites making a nice clean 2d game that works at any rez!
(6.54 KiB) Downloaded 491 times
iterationGAMES.com
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi jph_wacheski,

First of all, I think ZGE is a great tool in it's current state, capable of hosting a wide spectrum of applications with ease and elegance. However, since there is definitely room for improvement, I feel that the least I can do as non-Delphi/Pascal linguist is contributing by feedback and suggestions.

Concerning your feedback on my remark about ZGE not having a 2D system in place. ZGE in my eyes is tailored towards a 3D mindset in all of it's assets ( with the exception of CollisionStyle: Rect2D ) and therefore believe it would not be beneficial to implement strict 2D functionalities such as "point_direction(x,y,x2,y2)".

The reason for the X/Z axis movement in Ville's example is purely a matter of preference. This preference is reflected by the fact that ZGE considers the Y-axis being "up" by default ( CameraRotation = 0,0,0 ), which is a rather common approach in 3D technology ( Maya, XSI, Gamebryo, Unity3D etc. ).

And I agree that a ZGE-powered killer app which openly promotes the platform will help getting more people on board 8)

Peace & Love ~
Kjell
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

Thanks guys, having you two on the forum with your feedback and suggestions have been very motivational and rewarding for me as I get to see that ZGE really can be useful in the way I originally envisioned.

So it's not frustrating at all! The only thing bothering me is that the script-support is a major hurdle for making more advanced games, and that I don't have the time to properly deal with that currently as I'm busy with my day-job and my team-work with Cactus (Lo-Fi Minds).

Also thanks for offering to help. Assistance with forum moderation and tutorials are appreciated, and I may get back to you about that later.

jph - that rotation demo has got some really good controls and movement. Nice!
Post Reply