Author Topic: Spawn in Front  (Read 348 times)

Legacy_Sydious

  • Full Member
  • ***
  • Posts: 116
  • Karma: +0/-0
Spawn in Front
« on: July 16, 2011, 07:43:15 am »


               How would I go about creating something in front of the pc?

When I use:

oSpawn = CreateObject(OBJECT_TYPE_PLACEABLE, "thing", GetLocation(oPC));

it creates it AT the spot of the PC of course. PC slides to the side or back or forward.(Im sure you know what I mean.)

I have tried the GetAheadLocation(oPC) but that spawns way to far in front. Need it right in front. Like where their hands would be during a get from low animation

Any tips?
               
               

               


                     Modifié par Sydious, 16 juillet 2011 - 07:24 .
                     
                  


            

Legacy__six

  • Hero Member
  • *****
  • Posts: 1436
  • Karma: +0/-0
Spawn in Front
« Reply #1 on: July 16, 2011, 02:10:11 pm »


               Perhaps not the easiest way to do it, but I don't know nwscript massively well (although if there's a standard function, this is what the engine will be doing for you anyway).

vector vPos = GetPosition(oPC);
float fFacing = GetFacing(oPC);
float fDistAway = 1.0f;

vPos.x += cos(fFacing) * fDistAway;
vPos.y += sin(fFacing) * fDistAway;

object oSpawn = CreateObject(OBJECT_TYPE_PLACEABLE, "thing", Location(GetArea(oPC), vPos, fFacing));


Essentially what you're doing is finding a point on a circle around the PC of a short distance away, dependant on the angle s/he's facing - as all points of a set distance away from any point form a circle around it.
               
               

               


                     Modifié par _six, 16 juillet 2011 - 01:14 .
                     
                  


            

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
Spawn in Front
« Reply #2 on: July 16, 2011, 02:26:39 pm »


               You could place a waypoint at whatever the PC is manipulating and spawn the object at the waypoint, but I think vectoring would work better.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Spawn in Front
« Reply #3 on: July 16, 2011, 02:30:28 pm »


               For setting the position of something you can use #include "x0_i0_position"

and call one of the relevant functions. You might want GetAheadLocation(oPC) but to modify it so that the position is closer

For better customized locations you can use GenerateNewLocation
GenerateNewLocation(oPC, DISTANCE_TINY, GetFacing(oPC), GetFacing(oPC));
               
               

               


                     Modifié par henesua, 16 juillet 2011 - 01:35 .
                     
                  


            

Legacy_Sydious

  • Full Member
  • ***
  • Posts: 116
  • Karma: +0/-0
Spawn in Front
« Reply #4 on: July 16, 2011, 07:30:12 pm »


               Great help as always. Thanks!
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Spawn in Front
« Reply #5 on: July 17, 2011, 01:35:53 am »


                 Where _six normally goes the trig route with his solutions to problems like this,  I myself find it easier to get my solution using vectors.  Do not get me wrong here, there is nothing wrong with the trig solution given by _six, this is just another way to solve the same problem. 

here is Six's code converted to a vector style.

vector vPos = GetPosition(oPC);
float fFacing = GetFacing(oPC);
vector vFacing = AngleToVector(fFacing );
float fDistAway = 1.0f;

vPos += vFacing * fDistAway;

object oSpawn = CreateObject(OBJECT_TYPE_PLACEABLE, "thing", Location(GetArea(oPC), vPos, fFacing));


*********  
  A vector is a set of cordinats that defines a  direction and a magnitude.  

All the code segment does is take the facing of the PC and turn it into a vector.  adjusts the magnitude of the vector by multiplying it by the distance. then added it to the PC's postion.to get the spawn point.   

*******
@henesua;  I do not like to use the "x0_i0_position" include.  The first time I used it I found it had a bug in the function I was trying to use.  I do not remember what the function was at the moment just that it did not return the desired results.  I have not used the include since.   Just a warning, If you use it a lot make sure you fully test your results. 
               
               

               


                     Modifié par Lightfoot8, 17 juillet 2011 - 12:41 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Spawn in Front
« Reply #6 on: July 18, 2011, 03:59:18 am »


               @Lightfoot. Thanks. I haven't encountered a bug yet, but I'll keep an eye out.