Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Pedestrian Waypoints / Object names in 3D max

Author
Message
Ramon156
13
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 4th Apr 2012 17:25
Hi guys. I've searched for this for quite a while but can't really find a sollution or a way to implement this into my game.
For my main game (Top camera view GTA-style), I want to have pedestrians walk on a sidewalk and use roads / traffic lights to not get killed (just by the player Muahaha!).

Pedestrians are simply just objects moving around.
This code can be edited and expanded to fit the programmers needs, pedestrians for example turn 2 deg. a frame instead of instantly turning 90 degrees etc.


I am now trying to move an object between 2 waypoints.
These 2 waypoints are boxes I've created in 3DSmax.
I've named those Objects in 3DSMax "PED.WP.1" and "PED.WP.2"
I do select both of my waypoints(objects) in 3DSmax and export the selected objects as Waypoints.X according to the map coordinates.
They show up fine in my game at the right place (They will be hidden later).

Question 1 :
Is it possible to "select" these names/objects used in 3Dsmax in dbpro?

Question 2 :
Is this a "good" way to do this, or should I consider a different kind of method to use waypoints or however you want to call them.

Using darkbasic pro objects I got it to work, the object will move from a to b, rotate, and go back.

For choosing between waypoints I'd have no idea how to do this.

The part I'm having trouble to understand is how you could check if a waypoint is connected to the waypoint you're at. And how would you check if there's nothing between those waypoints blocking the path.

Here's a video showing my progress untill now.
I have absolutely no idea why I added a part showing the 2 waypoints, I think it's just to give a visual of my "map".

http://www.youtube.com/watch?v=gf2alMg5Iqg&feature=youtu.be
zeroSlave
15
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 4th Apr 2012 22:48
Do a checklist for limbs to get the names of the objects. Check this out:


I attached the .x file. It's got three limbs. "WayPoint.1", "WayPoint.2", and "Ground"

Attachments

Login to view attachments
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 5th Apr 2012 01:16
First off, I had no idea that you could give limbs names and then extract those names with DBP. You learn something new everyday.

The way I approached the whole way point thing is to give each npc a path, made up of as many way points as you want. When the npc reaches the current way point they are walking toward (this can be determined by calculating the distance between the way point) simply have the npc go to the next way point. I also found it simplified things if I used a "looping path", ie one that when the npc reaches the last way point they start to walk toward the first first point. In your case you only have two way points so this is what's going to happen anyway.

Below is a practice demo I created, it has some maths to work out which direction to turn the npc which you may be able to improve upon.



If you want to have your npcs going up hills, ramps, stairs etc, then you use the same approach but use a simple ray cast downward to work out where the ground is to determine what the y coordinate of the npcs needs to be. You don't have to give the way points a y coordinate, just keep the xz cooridates and let the ray cast deal with the the y position for you. I've used this basic method and it works pretty well, with all my npcs walking around, happily going up and down stairs.

This is only one approach and it's pretty simple, I suspect that if you have dozens of npcs then giving each their own path may not be possible but what you could do is allocate a single path to a number of npcs and have them all start at a differen point. In the demo above, you could easilly have four npcs per path, for instance.

As you can see, I've got the way point positions in data blocks within the code, but I would recommend using zeroSlave's method of extracting the limb data and writing that to an array instead.

Thinking about it, to get the connectedness of your way points (ie what to way points make a path and I'm also thinking that everything I've written has answered your question) all you need to do is name your limbs in a structured manner so you can use the string commands to slice up the name so you can code how to write the limb data to the array. For instance you currently have the limb names "PED.WP.1" and "PED.WP.2". If you changed this to "PED.WP.1.S" and PED.WP.1.E", this would then slice up to mean:

PED = predestrian (I'm guessing here)
WP = waypoint (again, I'm guessing)
1 = the ident number of the path
S = start point
E = end point

so:

PED.WP.2.S = start point of path 2
PED.WP.2.E = end point of path 2
PED.WP.3.S = start point of path 3
PED.WP.3.E = end point of path 3

and so on.

I've only just thought of this and it's getting late so I don't have time to do an example but hopefully this is making sense to you.
Ramon156
13
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 5th Apr 2012 16:53 Edited at: 8th Apr 2012 16:58
Getting really frustrated now.
Please tell me where I'm going wrong.




In the main Loop I refer to "Move_NPC"


Move_NPC:



The NPCS do :

Start at WP_1 or WP_2
They move from that waypoint to the next Waypoint. Then they start rotating at the waypoint and sometimes "bump" a bit to a side. It's like they want to move but get forced back into the turning loop.

When their distance < 20 to the waypoint.
Way_Point(i).Current keeps increasing forever.
Turning this Dist<20 check off does not affect anything, the NPCS still do move and start to rotate.

I am not sure what's wrong in the code, it could be so many things but my guess is the OPP and ADJ calculation.
Ramon156
13
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 14th Apr 2012 17:25
The code from 29-games is working. Made a new empty project for about 20 times before I got it.. about right.

I'm reading Limb names and putting them in an array.
After that I'm checking for the correct string and assign limb x and z positions to a different array.

I've also got some minor problems:
Here's the piece of code that's guilty of doing it.



Printing the names$ array shows the following :



Why does it show only 4 waypoint names, if there's 5?
Why is 0 and 1 empty?
Why do the NPCS use 5 waypoints while it only prints out 4?

How can I make it so array Names$ slot 1 = waypoint001 and it increases instead of the other way around.

Using commands as array insert at bottom just crashes my game.

Little video for visuals :
http://www.youtube.com/watch?v=WOUsEHFLx5Q&feature=youtu.be

Thank you
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 16th Apr 2012 22:17
I think you're getting confused between limb numbers and way point number.

In your piece of code you have this



Here you have j-1 as the limb number when it's actually the way point number. The two are not related.

All you really need to do is add in a bit where you are writing the limb number to a variable - which is not the same as x but actually (x-1) - then use this instead of (j-1).

Below is a piece of code that scans through a model looking for way points and then writes the limb position to an array.

Just to confuse matters, I'm using a type for the way point array instead of the 3 dimensional array I originally used (I've sort of lifted this out of something else I'm working on).

I've added in a bit extra where you can use the up arrow key to cycle through and highlight each path in turn (paths are highlighted by green and red spheres at the way point).




As mentioned in the comments, the format of the naming convention used for the waypoint limbs is:

waypoint_pp_ww

where pp is the path number and ww is the waypoint number

This allows for up to a 99 paths and 99 waypoints in each path (unless you count from 0 in which case this'll be 100). You will need to use this format in your model if you want to run the code as is.

I've added a down load of the model I used to test this code (along with the code itself and project file) so you can run it yourself and see how it all works. In here the cone mark the waypoints and the cubes are just extra limbs so you can see they don't interfere.

You can obviously use whatever naming convention you like and change the code accordingly.

If you want more way points in each path then you will need to change the "number_of_waypoints_per_path" and then make sure your model matches to suit. However, I'm sure there is a way of having the model control everything but I couldn't quite figure it out so I went with the simple method for now.

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-22 00:32:06
Your offset time is: 2024-11-22 00:32:06