Author Topic: Get Location on opposite side of door  (Read 562 times)

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Get Location on opposite side of door
« on: January 24, 2012, 03:37:56 pm »


                I could use some help with a script which gets a location on the opposite side of a door. The location would preferably be 1 meter from the door, and must be on the other side from than that which the PC is currently on. The door in question has no transition destination. Its simply a door in the middle of an area, separating two rooms or the like.  

The two pieces of data are:
(1) the PC that used the door
(2) the door itself.



I've tried manipulating vectors, but then realized that I don't know how to convert a vector to a location.

Another approach could identifying two locations, each directly in front of the door but on opposite sides, and then determining which is clsest to the PC. But that seems like more than is necessary. I'm looking for another solution if possible.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Get Location on opposite side of door
« Reply #1 on: January 24, 2012, 05:29:22 pm »


               Try reading location vector   and http://social.biowar...33245/1#7405205
and Spawn in Front

IT has been explaind a few other times on the boards, If you are still having trouble when I get home Ill help more then.
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Get Location on opposite side of door
« Reply #2 on: January 24, 2012, 05:34:30 pm »


               

henesua wrote...
I've tried manipulating vectors, but then realized that I don't know how to convert a vector to a location.


Input three floats (x, y, and z location in area) to make a vector with

vector Vector(float x=0.0f, float y=0.0f, float z=0.0f):


vector vVec = vector(2.0, 18.2, 0.0);

Then you just need facing and area to get a location with

location Location(object oArea, vector vPosition, float fOrientation)

Area is usually gotten with GetArea from OBJECT_SELF or whatever is handy (like the door, here). Facing often doesn't matter, you can just enter 0.0 unless you 're spawning in something you want facing a particular way:


object oArea = GetArea(OBJECT_SELF);
location lLoc1 = Location(oArea, vVec, 0.0);

Funky
               
               

               


                     Modifié par FunkySwerve, 24 janvier 2012 - 05:35 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Get Location on opposite side of door
« Reply #3 on: January 24, 2012, 06:30:49 pm »


               Thanks, thats useful information. I looked in position as well, and found found the same information. I should have dug deeper before bothering you. But I do appreciate it. Thank you very much. I am sure it will help others too. I think doing some vector math should be more efficient than two getdistancebetween functions. I'll make the change to my script.

And now mice can squeeze under doors! Perhaps it will make for a Pass Door spell too.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Get Location on opposite side of door
« Reply #4 on: January 24, 2012, 11:21:13 pm »


               ... lol, I love it...

void RunRatUnderDoor(object oRat, object oDoor)
{
   // Get the posistion for the rat.
   vector vRat = GetPosition(oRat);

   // Get the position for the door
   vector vDoor = GetPosition(oDoor);

   // Subtract the position of the rat from the position of the door.
   // To get the vector representing the position of the rat from the door.
   // basicly what we are doing is both the rat and the door have (X,Y) positions
   // (Rx,Ry) and (Dx,Dy)
   // if we subtract the position of the rat from both of them in effect moving
   // the line segment to where the rat is at cords (0,0) the
   // (Rx,Ry) - (Rx,Ry) =  (0,0)
   // (Dx,Dy) - (Rx-Ry) =  (Dx-Rx,Dy-Ry)
   // in effect moving the line segment to where the rat is at cords (0,0) the
   // the (Dx-Rx,Dy-Ry) Is in effect the vector showing both distance and
   //Direction that the door is from the rat.
   vector vDoorFromRat = vDoor-vRat;

   //To get the position 1 unit beyond the door in a stright line from where
   // the rat currently is, all we have to do is normilize the vector and add
   // it to the position of the door.
   vector vPastDoor1M = vDoor + VectorNormalize(vDoorFromRat);

   //Build a location with the new vector and have the rat face in the same
   //Direction that the door was from him. .
   location lPastDoor = Location(
                                   GetArea(oRat),
                                   vPastDoor1M,
                                   VectorToAngle(vDoorFromRat)
                                 );
 
   // Clear rats action que
   AssignCommand(oRat,ClearAllActions(TRUE));

   //Run to the door
   AssignCommand(oRat,ActionMoveToObject(oDoor,TRUE));

   //Lay flat
   AssignCommand(oRat,ActionPlayAnimation( ANIMATION_LOOPING_DEAD_FRONT,1.0,2.0));

   // Squezze under.
   AssignCommand(oRat,ActionJumpToLocation(lPastDoor));

}


EDIT: Yes, I used more vars then I need to.  That was just to make it easier to see what was going on.  
               
               

               


                     Modifié par Lightfoot8, 24 janvier 2012 - 11:24 .
                     
                  


            

Legacy_ShadowM

  • Hero Member
  • *****
  • Posts: 1373
  • Karma: +0/-0
Get Location on opposite side of door
« Reply #5 on: January 24, 2012, 11:27:04 pm »


               LOL I just had to post I love what you named the custom function.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Get Location on opposite side of door
« Reply #6 on: January 24, 2012, 11:31:08 pm »


               Awesome! Thanks! That is very similar to what I am doing. I may modify my function to resemble yours.

One thing however... can you jump a rat that is in the LOOPING_DEAD_FRONT animation? I'll try it. But my assumption was that no jumping would work while a character is busy in an animation.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Get Location on opposite side of door
« Reply #7 on: January 24, 2012, 11:35:27 pm »


               

henesua wrote...

Awesome! Thanks! That is very similar to what I am doing. I may modify my function to resemble yours.

One thing however... can you jump a rat that is in the LOOPING_DEAD_FRONT animation? I'll try it. But my assumption was that no jumping would work while a character is busy in an animation.


When I ran the function above,  Iexpected the rat to stay down then jump.  I was amazed when I watched him slide under the gate I was testing with. 
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Get Location on opposite side of door
« Reply #8 on: January 24, 2012, 11:37:37 pm »


               Wow. I will definitely play with that.

I'll try different models. Snakes, oozes, that tiny mouse, the rat. I hope they all behave the same way so that they can all take advantage of this ability. Would be an interesting add on for the blocked event.

But for now it will be tested in game play for possessed mouse familiars.
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Get Location on opposite side of door
« Reply #9 on: January 27, 2012, 02:09:03 am »


               

Lightfoot8 wrote...

henesua wrote...

Awesome! Thanks! That is very similar to what I am doing. I may modify my function to resemble yours.

One thing however... can you jump a rat that is in the LOOPING_DEAD_FRONT animation? I'll try it. But my assumption was that no jumping would work while a character is busy in an animation.


When I ran the function above,  Iexpected the rat to stay down then jump.  I was amazed when I watched him slide under the gate I was testing with. 

Very small jumps (a few meters) result in a sliding animation rather than a disappear/appear.

Funky
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Get Location on opposite side of door
« Reply #10 on: February 02, 2012, 01:57:06 pm »


               Here's the pass door spell

Thanks a lot for the help everyone. The function is working very well, Lightfoot8.
               
               

               


                     Modifié par henesua, 02 février 2012 - 02:43 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Get Location on opposite side of door
« Reply #11 on: February 03, 2012, 12:50:24 am »


               Ok I do not understand one thing you did here.  

118.           float fFace = GetFacing(oDest);
119.
120.            if (fFace<180.0)
121.                fFace=fFace+179.9;
122.            else
123.                fFace=fFace-179.9;

I can see the point if the doors are always on the external boarders of the area.   But what happens if  it is a door that is comming out of a building in the middle of an area?    or am I reading this wrong?
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Get Location on opposite side of door
« Reply #12 on: February 03, 2012, 01:07:51 am »


               On almost every door that crosses a transition in my mod I was showing up behind the door after the transition, and always facing the door when I arrived. So I simply reversed the facing, and its been working well ever since.

All the doors in question have had that arrow symbol facing into the area. Basically the arrow appears to point in the opposite direction of the door's facing. I hope that this is 100% consistent behavior. If not, I'll have to write a more sophisticated script.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Get Location on opposite side of door
« Reply #13 on: February 03, 2012, 02:42:58 am »


               ok,  I had a brain fart,  You are always moving the angle 180 degrees,  It If statment threw me.   yes the facing of the door is in the opposite direction that the arrow points.    So you are always jumping the caster to the side of the door the arrow is pointing and stright in front of it. If you do not mind me critiquing a little bit.   It is simpler for me to do it this way. 

...
// No reason to worry about it being out of range.   if it bugs you a simple %360 would do the trick
float fFace = GetFacing(oDest)+180; 

//AngleToVector(fFace) will give you the a vector that is already normilized with a length of 1. 
// From there all you need to do is add it to the position of the door.  
vector vNewPos = GetPosition(oDest) +  AngleToVector(fFace); 

//Then right back to what you had.
location lPastDoor = Location(
                                GetArea(oDest),
                                vNewPos,
                                fFace
                            );
... 


               
               

               


                     Modifié par Lightfoot8, 03 février 2012 - 02:44 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Get Location on opposite side of door
« Reply #14 on: February 03, 2012, 03:52:43 am »


               That works well. Thank you.

I didn't know about AngleToVector. There are many vector functions in NWN that I am not aware of. Its taking some getting used to.