Aller au contenu

Photo

location vector


  • Veuillez vous connecter pour répondre
3 réponses à ce sujet

#1
Sydious

Sydious
  • Members
  • 59 messages
Im trying to have ceatures spawn at a random spot near a waypoint. I can't seem to figure out how to set the vector I need. Can anyone help?

This is my spawn script. Right now on a switch. Will be placing it in the onEnter of the area I think.

#include "x0_i0_position"
void main()
{

    object oSpawn;
    object oSpawnPoint;
    oSpawnPoint = GetWaypointByTag("SP_COMMONER_01");
    int iCrowd_Size = GetLocalInt(oSpawnPoint, "crowd_size");
    //Locate the area we are in
    object oArea = GetArea(OBJECT_SELF);
    //Locate where in the are we are
    vector vPosition = GetPosition(oSpawnPoint);
    //Identify the direction we are facing
    float fOrientation = GetFacing(oSpawnPoint);
    //Create a new location with this information
    location myLocation = Location( oArea, vPosition, fOrientation);
    //Create Crowd
    int i;
    for (i = 0; i < iCrowd_Size; i++)
    {
        int iGender = d2(1);
        CreateObject(OBJECT_TYPE_CREATURE, "commoner00" + IntToString(iGender), myLocation, FALSE, "commoner_" + IntToString(i));
    }
}

#2
Axe_Murderer

Axe_Murderer
  • Members
  • 279 messages
[nwscript]
#include "nw_i0_spells"  // defines the GetRandomDelay function.

void main()
{
...
float fMaxDistance = 5.0; // max dist from waypoint where random loc will end up.
float fDistance = GetRandomDelay( 0.0, fMaxDistance ); // random distance from waypoint
vector vRandom = VectorNormalize( AngleToVector( GetRandomDelay( 0.0, 360.0 ))); // random dir from waypoint
vRandom *= fDistance;
vRandom += GetPosition( oSpawnPoint );
location myLocation = Location( oArea, vRandom, GetFacing( oSpawnPoint ));
...
}
[/nwscript]

Modifié par Axe_Murderer, 12 juillet 2011 - 06:35 .


#3
henesua

henesua
  • Members
  • 3 883 messages
Look for the position script amongst nwn's generic scripts. Just search for "position" amongst all scripts in a module. You will find it.

It has a function that generates random locations. You can modify this to find a random location within a certain distance of another object. I have done something very similar to what you are trying recently. If you can't figure it out, I'll dig up my scripts and post a snippet for you.

#4
Sydious

Sydious
  • Members
  • 59 messages
Perfect.

Thanks for your help all.