Jump to content

Need help with a math problem


tenb1

Recommended Posts

Can anyone help me with this?

 

I'm trying to get an autofacing script to work, but my maths kinda sucks, what I'm trying to do is to get the relative position and angle of the player, and then make an NPC face the player at a reciprocal angle (+180 degrees) at 50 units distance

 

Now I got the angle to work properly, but just adding +50 units to the X and Y position obviously doesn't cut it. I've put down what I've done below.

 

set XPos to Player.GetPos x (Not sure how this part will look)

set YPos to Player.GetPos y (Ditto with this one -_-)

set ZPos to Player.GetPos z

set APos to Player.GetAngle z +180

 

Can anyone help out a noob here? >.<

Link to comment
Share on other sites

Can anyone help me with this?

 

I'm trying to get an autofacing script to work, but my maths kinda sucks, what I'm trying to do is to get the relative position and angle of the player, and then make an NPC face the player at a reciprocal angle (+180 degrees) at 50 units distance

 

Now I got the angle to work properly, but just adding +50 units to the X and Y position obviously doesn't cut it. I've put down what I've done below.

 

set XPos to Player.GetPos x (Not sure how this part will look)

set YPos to Player.GetPos y (Ditto with this one -_-)

set ZPos to Player.GetPos z

set APos to Player.GetAngle z +180

 

Can anyone help out a noob here? >.<

 

The z angle is 0-360 and aligned to the north marker (y axis) and grows clockwise. To use trigonometry with it some conversion is need as to find the correct direction on the trigonometric circle (that have 0 on the X axis and grows contra-clockwise).

 

Following the wiki CS Manual:

 

float GameAngleZ ;the game's version

float TrigAngleZ ;the rest of the world's interpretation of the same

 

set GameAngleZ to player.GetAngle Z

 

if ( GameAngleZ < 90 )

set TrigAngleZ to 90 - GameAngleZ

else

set TrigAngleZ to 450 - GameAngleZ

endif

 

But for your problem nothing of this is important and you shall care only with values of Zangle > 180 which is meaningless if added 180 in angle terms. Here I shall point you to avoid using "pos" for angles in the name of the cleanness. So you may use the following code block

 

float Zangle ; Player's direction

float Aangle ; facing opposed the player

 

set Zangle to Player.GetAngle Z

 

If Zangle < 180

Set Aangle to Zangle + 180

Else

Set Aangle to Zangle - 180

Endif

 

PS: Care must take with Z angle and free camera movements, like when hiding a horse.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...