Jump to content

Get forward


den1

Recommended Posts

All I want to do is to move the target to there player is aiming at + 100 units forward. How I do that?

 

This doesn't do it right:

float PX = game.getPlayer().GetPositionX() + game.getPlayer().GetAngleX() * 100;
float PY = game.getPlayer().GetPositionY() + game.getPlayer().GetAngleY() * 100;
float PZ = game.getPlayer().GetPositionZ() + game.getPlayer().GetAngleZ() * 100;
target.SetPosition(PX,PY,PZ);

or this:

float PX = game.getPlayer().GetPositionX() + Math.cos(game.getPlayer().GetAngleX()) * 100;
float PY = game.getPlayer().GetPositionY() + Math.cos(game.getPlayer().GetAngleY()) * 100;
float PZ = game.getPlayer().GetPositionZ() + Math.cos(game.getPlayer().GetAngleZ()) * 100;
target.SetPosition(PX,PY,PZ);

Notice that the target DOES move, but to completely wrong position (inside walls etc.).

Edited by den1
Link to comment
Share on other sites

You need to use the translate function instead of setposition, it should look something like this..

float PX = game.getPlayer().GetPositionX() + game.getPlayer().GetAngleX() * 100;
float PY = game.getPlayer().GetPositionY() + game.getPlayer().GetAngleY() * 100;
float PZ = game.getPlayer().GetPositionZ() + game.getPlayer().GetAngleZ() * 100;
target.TranslateTo(PX,PY,PZ,0,0,0,SpeedYouWant(carefulwiththisvariable),0);

Target needs to be declared either as an actor or objectreference property, else im not sure if angleX,y,z return a direction vector, that probably will set the object or actor in an odd position, anyway if it does return direction vector let me know, I have a few ideas to work with that, the translate instead of setting an instant position will move the object or whatever through the air so in any case it may help you debug, good luck ^^.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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