|
Post by MonstaWolf on Feb 18, 2016 14:28:54 GMT
Hello. I'm currently trying to make a script where the object I'm trying to change the location of goes to the Vector3 point closest to the current location (CurrentLoc). I know that this script will just bring it to wherever the CurrentLoc is, because I had no clue where to go about this. (CurrentLoc is a Vector3 btw)
(Also, if someone could put that into a code box for me, I'd appreciate it)
void Main() {
if(iInitializing()) { iObjectLocation(OBJ_198,CurrentLoc);
//Waypoints: Waypoints[9] = Vector3( 8.18507,0.12,12.6025 ); Waypoints[0] = Vector3( 7.94164,0.12,92.5283 ); Waypoints[1] = Vector3( 7.81209,0.12,211.348 ); Waypoints[2] = Vector3( 8.9646,-2.96942,456.604 ); Waypoints[3] = Vector3( -7.35023,-2.92572,473.776 ); Waypoints[4] = Vector3( -132.649,0.12,475.11 ); Waypoints[5] = Vector3( -155.259,0.12,456.63 ); Waypoints[6] = Vector3( -154.808,0.12,210.514 ); Waypoints[7] = Vector3( -155.595,0.12,2.53415 ); Waypoints[8] = Vector3( -6.82511,0.12,1.77454 );
// spawn car
SpawnLocation=iFloatRand(0,0);
CurrentWayPoint= SpawnLocation+1;
iObjectLocationSet(BODY, CurrentLoc);
iObjectOrientationSet(BODY, QuatGetLookAt(Waypoints[SpawnLocation], Waypoints[CurrentWayPoint]));
|
|
|
Post by Power Supersport on Feb 18, 2016 19:24:01 GMT
Hey, MonstaWolf ... I think I have a quick solution... Of course, you will spice it up if needed... Vector3 [] Waypoint(10); Vector3 CarLoc; // Car location Vector3 ClosestLoc;
void Main() {
iObjectLocation(OBJ_0,CarLoc);
Waypoint[9] = Vector3(8.18507,0.12,12.6025); Waypoint[0] = Vector3(7.94164,0.12,92.5283); Waypoint[1] = Vector3(7.81209,0.12,211.348); Waypoint[2] = Vector3(8.9646,-2.96942,456.604); Waypoint[3] = Vector3(-7.35023,-2.92572,473.776); Waypoint[4] = Vector3(-132.649,0.12,475.11); Waypoint[5] = Vector3(-155.259,0.12,456.63); Waypoint[6] = Vector3(-154.808,0.12,210.514); Waypoint[7] = Vector3(-155.595,0.12,2.53415); Waypoint[8] = Vector3(-6.82511,0.12,1.77454);
for (int i=0; i<10; i++) { if (iVectorLength(Waypoint[i]-CarLoc) < ClosestLoc) { ClosestLoc = Waypoint[i]; } } } I really hope this works because I didn't tested it... So... tell me if it works or not...
|
|
|
Post by MonstaWolf on Feb 18, 2016 19:26:49 GMT
Power Supersport I'll try it soon, my computer is overheating it looks good, can't wait to see if it works. If it does, then with a bit of work, this'll mean much thicker traffic without the lag!
|
|
|
Post by Power Supersport on Feb 18, 2016 19:58:20 GMT
Wait... you want to use it for traffic system? The "closest point" method is not gonna work...
|
|
|
Post by MonstaWolf on Feb 18, 2016 23:10:58 GMT
Wait... you want to use it for traffic system? The "closest point" method is not gonna work... I already thought of how I was going to use it. I'm not making it the closest point to the car, but to a skinmesh which is attached to it, which is pretty far away from it. There obviously are not going to be 10 points, but a ton of points placed around the entire map in what will most likely be one massive path. The city won't be massively populated, but having that system combined with a scripted vehicle that randomly switches models (so there are many different possible cars when it spawns) should be substantial to what I'm hoping for. (I hope I described it well enough XP) Do you have a different idea? Like always, I'd consider it.
|
|
|
Post by MonstaWolf on Feb 22, 2016 14:37:02 GMT
I'm working on it right now, trying to implement that snippet into the overall traffic script. It seems to work for the most part, but the traffic car doesn't spawn directly on the point.
I have it set up like this (I have all of the variables, but there are a ton for this script and it would just make it look more confusing to post that):
void Main() {
if(iInitializing()) { iObjectLocation(OBJ_198,CarLoc);
//Waypoints: Waypoints[9] = Vector3(8.18507,0.12,12.6025); Waypoints[0] = Vector3(7.94164,0.12,92.5283); Waypoints[1] = Vector3(7.81209,0.12,211.348); Waypoints[2] = Vector3(8.9646,-2.96942,456.604); Waypoints[3] = Vector3(-7.35023,-2.92572,473.776); Waypoints[4] = Vector3(-132.649,0.12,475.11); Waypoints[5] = Vector3(-155.259,0.12,456.63); Waypoints[6] = Vector3(-154.808,0.12,210.514); Waypoints[7] = Vector3(-155.595,0.12,2.53415); Waypoints[8] = Vector3(-6.82511,0.12,1.77454);
for (int i=0; i<10; i++) { if (iVectorLength(Waypoints-CarLoc) < (iVectorLength(ClosestLoc))){ ClosestLoc = Waypoints; } } int i=0; i<10; i++; // spawn car
SpawnLocation=iFloatRand(0,0);
CurrentWayPoint= i+1;
iObjectLocationSet(BODY, ClosestLoc);
iObjectOrientationSet(BODY, QuatGetLookAt(Waypoints, Waypoints[CurrentWayPoint]));
|
|
|
Post by MonstaWolf on Feb 22, 2016 15:42:06 GMT
Would you like me to post the whole script?
|
|
|
Post by Power Supersport on Feb 22, 2016 15:44:21 GMT
Well... there is no actual full script...
It's what you see... have written it while I was posting...
So, you want a car to spawn just near the closest point of you?
|
|
|
Post by MonstaWolf on Feb 22, 2016 16:22:58 GMT
No, I meant my full script. The part that I gave you was the part that spawns the car. The car is made up of multiple objects (none of them being the "car" object ironically) and I just need ClosestLoc to be the closest waypoint. I think I've got it working how I want it, though, so thanks for the help.
|
|
|
Post by Power Supersport on Feb 22, 2016 16:43:37 GMT
Sorry... the misunderstanding... Well, you don't need to post your entire script here... because it's your property... I need to think on this... Give me some time and I will give you the solution of closest position selection...
|
|
|
Post by MonstaWolf on Feb 22, 2016 17:00:24 GMT
I got it to work, but 25% of the time it fails due to another script. I'm working on it. Once I do this, I need to create one big path that goes throughout the city so it always has a place to spawn
|
|
|
Post by MonstaWolf on Feb 23, 2016 22:15:58 GMT
After a ton of tweaking of many things in the project, I am proud to say that it works near-flawlessly! Thanks a ton!
|
|
|
Post by Power Supersport on Feb 24, 2016 15:07:24 GMT
OMG I want to see it... Do you have any plans for releasing a short trailer or a short demo?
|
|
|
Post by MonstaWolf on Feb 24, 2016 15:50:49 GMT
Not yet, I still need to place tons of points around the map as well as work on the rest of the game some more. I don't work on it tooo often, so I'm still working on the physics and the way the game plays in general
|
|
|
Post by Power Supersport on Feb 24, 2016 15:55:05 GMT
Ok, I am looking forward to it...
|
|
|
Post by MonstaWolf on Feb 24, 2016 16:23:06 GMT
It's funny, ever since I started development, I've had ideas for the trailer that I think about often.
|
|
|
Post by Power Supersport on Feb 24, 2016 16:30:44 GMT
And that's good... You always need to have ideas... not only about the trailer... but for your entire game...
|
|
|
Post by MonstaWolf on Feb 24, 2016 16:33:32 GMT
And that's good... You always need to have ideas... not only about the trailer... but for your entire game... Yeah I just played what I have so far, and I'm quite proud of it. I just need to get rid of the instability/lag
|
|