Author Topic: Need Help With SetFacingPoint Problem  (Read 547 times)

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Need Help With SetFacingPoint Problem
« on: January 30, 2016, 01:26:48 am »


               

I have a script that uses SetFacingPoint like this



...   
    vector vFace = GetPosition(oPC);
    SetFacingPoint(vFace);
...

to get a placeable to face a PC. Except for one really annoying detail it works perfectly. Perhaps I misunderstood but I always thought that because when you paint a placeable down in the toolset, the green arrow that comes from the placeable was the direction that the placeable faced. I mention this because when I use SetFacingPoint the placeable faces in 180 degrees the opposite direction! I need it to work as I was expecting not the way it is currently working. Please help.


 


Thanks in advance.


 


TR



               
               

               
            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
Need Help With SetFacingPoint Problem
« Reply #1 on: January 30, 2016, 03:57:00 am »


               just adding 180 degrees should work.


vector vFace = GetPosition(oPC);
SetFacingPoint(vFace+180);
...
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Need Help With SetFacingPoint Problem
« Reply #2 on: January 30, 2016, 04:23:57 am »


               

A second call after SetFacingPoint to SetFacing(GetFacing(OBJECT_SELF)+180.0);   might be needed for objects that are oriented 180 from what you'd expect.



               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Need Help With SetFacingPoint Problem
« Reply #3 on: January 30, 2016, 08:10:49 am »


               It's really a problem with some placeable models.

Place the object without rotation to determine what its orientation actually is in the toolset. This might be 90, 180 or 270 degrees different to the blue arrow (or, more importantly, the intuitive face, such as the front of a bookcase).

As others have said, you just need to add that rotation, which can be stored as a local variable on the template (since it's a property of the model).
               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Need Help With SetFacingPoint Problem
« Reply #4 on: January 30, 2016, 12:35:40 pm »


               

Thanks guys. Failed.Bard's solution worked. For some reason with



SetFacingPoint(vFace+180);

I get failed arithmetic - invalid operand error.


 


TR 



               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Need Help With SetFacingPoint Problem
« Reply #5 on: January 30, 2016, 03:30:30 pm »


               You can't add a scalar to a vector. You need to add the angle to the facing, like Failed.Bard said.


Or use VectorToAngle to reduce everything to angles first.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Need Help With SetFacingPoint Problem
« Reply #6 on: January 30, 2016, 03:47:23 pm »


               

Try 

 
SetFacingPoint(vFace * -1.0);

 

 
Explanation: 

 


Your facing is a (x,y)  cord or a change in the x, y cord from your position.   


So it your currently facing at lets say a 45 deg. angle the x,y  cord will be (1,1) 


Multiplying that vector by -1 ( -1.0 has to be a float)   will multiply both the x and the y cord by -1 


giving you a new cord facing of ( -1, -1 )   facing the opposite direction.  


 


 


 


EDIT:   I misread the original function.  Using a negative vector with SetFacingPoint can give a point outside of the tile set as WhiZard pointed out below.     


               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Need Help With SetFacingPoint Problem
« Reply #7 on: January 30, 2016, 04:04:39 pm »


               

For those interested my last post in this thread will show you what I used this script for.


 


TR



               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Need Help With SetFacingPoint Problem
« Reply #8 on: January 30, 2016, 04:17:56 pm »


               

Looking at this a little deeper, Your code fragment is also not taking into account where the placeable is at. (assuming that the placeable is not at the (0,0) cord).  


 


To adjust for the position of the PC in relation to the placeable, subtract the position of the Placeable to the from the position of the PC.  


 


It should look something like this:



 object oPC; 
 vector vFace = GetPosition(oPC)-GetPosition(OBJECT_SELF);
 SetFacing( vFace);

If the object is still facing the wrong direction, your placable is facing 180 deg to the arrow drawn in the toolset.   It that case just reverse the order of the  PC and the placable in the subtraction above. 


 


Making it:   


 




 object oPC;
 vector vFace = GetPosition(OBJECT_SELF)-GetPosition(oPC);
 SetFacing( vFace);

Hope that helps.  


 


L8


 


 



Edit:  Changed SetFacingPoint  to SetFacing,   Code will now work correctly.  


There was no problem with ReadHands original code since I misread the function. 



               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Need Help With SetFacingPoint Problem
« Reply #9 on: January 30, 2016, 07:20:15 pm »


               

Lightfoot, you seem to misunderstand the command.


 


SetFacingPoint() does not make you face in the direction that vVector would indicate, but rather makes you face the position on the tileset that vVector states.


 


Thus SetFacingPoint(GetPosition(OBJECT_SELF) + Vector(1.0, 0.0, 0.0)); would cause you to face east.  So to use the command correctly to face the opposite direction as your target you would have to do SetFacingPoint(2.0*GetPosition(OBJECT_SELF) - GetPosition(oPC)), which may end up not even being a valid coordinate, as it could be outside of the tileset.



               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Need Help With SetFacingPoint Problem
« Reply #10 on: January 31, 2016, 01:26:00 am »


               


Lightfoot, you seem to misunderstand the command.


 


 




 


You are absolutely correct.   In fact I did not even know the SetFacingPoint function existed, I was reading it as SetFacing.  


 


Thank you for the heads up.    


 


Adding strikes  to my post above.   


 


I guess I am a bit rusty. 



               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Need Help With SetFacingPoint Problem
« Reply #11 on: January 31, 2016, 02:34:17 am »


               

Guys, if you think you can improve the pitiful scripts I wrote, please be my guests. Just follow the link in my previous post and scroll to the bottom of the page. There you will see the stone eye placeables that the scripts are for. Just click on the link to the file in my dropbox public folder to download the file. I placed it there so that if anyone can improve any part of it, they are welcome to do so.


 


FWIW, I didn't know about SetFacingPoint  either until I stumbled on it by accident.


 


TR



               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Need Help With SetFacingPoint Problem
« Reply #12 on: January 31, 2016, 04:18:38 am »


               


You are absolutely correct.   In fact I did not even know the SetFacingPoint function existed, I was reading it as SetFacing.  


 


Thank you for the heads up.    


 


Adding strikes  to my post above.   


 


I guess I am a bit rusty. 




 


 


SetFacing expects a float, you're inputting a vector, Lightfoot8.  You would need a   VectorToAngle(vector vVector)  call in there to convert it, and I'm not sure if you would't end up with the exact same thing as SetFacingPoint by using that method regardless.


 


Edit:


 


SetFacing(VectorToAngle(GetPosition(oPC) - GetPosition(OBJECT_SELF)));


or


SetFacing(VectorToAngle(GetPosition(OBJECT_SELF) - GetPosition(oPC)));


 


Would be the likely usages trying that method, I think.  I tend to think that the current method is likely most efficient, and it could be tailored to be more universal by adding in an offset variable as was suggested earlier in the thread.


 


 


SetFacingPoint(GetPosition(oPC));


SetFacing(GetFacing(OBJECT_SELF)+GetLocalFloat(OBJECT_SELF, "FACING_OFFSET"));


 


or somesuch.



               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Need Help With SetFacingPoint Problem
« Reply #13 on: January 31, 2016, 01:31:51 pm »


               


SetFacing expects a float, you're inputting a vector, Lightfoot8.  You would need a   VectorToAngle(vector vVector)  call in there to convert it, and I'm not sure if you would't end up with the exact same thing as SetFacingPoint by using that method regardless.


 


Edit:


 


SetFacing(VectorToAngle(GetPosition(oPC) - GetPosition(OBJECT_SELF)));


or


SetFacing(VectorToAngle(GetPosition(OBJECT_SELF) - GetPosition(oPC)));


 


Would be the likely usages trying that method, I think.  I tend to think that the current method is likely most efficient, and it could be tailored to be more universal by adding in an offset variable as was suggested earlier in the thread.


 


 


SetFacingPoint(GetPosition(oPC));


SetFacing(GetFacing(OBJECT_SELF)+GetLocalFloat(OBJECT_SELF, "FACING_OFFSET"));


 


or somesuch.




 


 


lol ,  boy I am rusty,   Again 100% correct.    


thank you


               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Need Help With SetFacingPoint Problem
« Reply #14 on: February 01, 2016, 01:26:18 am »


               


SetFacingPoint(GetPosition(oPC));
SetFacing(GetFacing(OBJECT_SELF)+GetLocalFloat(OBJECT_SELF, "FACING_OFFSET"));

If memory serves, the second line should be an ActionDoCommand, otherwise the GetFacing will return the original value at script execution time, rather than the modified value after the SetFacingPoint action.

Or add the offset into the VectorToAngle value in the previous examples (arguably easier).