Aller au contenu

Photo

vector question


2 réponses à ce sujet

#1
gordonbrown82

gordonbrown82
  • Members
  • 544 messages
vector vFinalPosition = Vector(vGaleOrientation.x * 2.0 + vGalePosition.x, vGaleOrientation.y * 2.0 + vGalePosition.y, vGalePosition.z);

that code creates a position in front of the gale creature but i don't understand how. Why is the orientation taken times 2? What is the x component of vGaleOrientation?

#2
DavidSims

DavidSims
  • BioWare Employees
  • 196 messages
An orientation vector is a way of showing where an object is facing. Essentially, it is the x, y and z co-ordinates of a point exactly 1 distance in front of the object, in the direction the object is facing, using the creature’s position is the origin. Typically the z value is 0, because creatures can't face up and down.



This means if the creature is facing forward in the x direction, the vector will be (1, 0, 0) and if it's facing forward in the y direction it will be (0, 1, 0). If it's facing at 45 degree between those two directions it will be (0.707, 0.707, 0).



If you’re trying to find a point say 2m in front of an object, you need to know how much of that 2m to add to the x direction and how much to add to the y direction. If you just tried to always say add 2 to the creature’s x coordinate, you’d always get a point 2m away from the creature, but it wouldn’t necessarily be in front of the creature. It might be behind or to the side, depending on where the creature is facing.



The creature's orientation vector is a handy shortcut to find out how much to add to the x and how much to add to the y, saving you some trigonometry. Because it's already a point 1m in front of the creature, all you have to do is multiply the coordinates to get any distance from the creature you want. You then have to add in the position of the creature, otherwise you'd be 2m in front of whatever dark corner of the level happens to be (0,0,0).



Hopefully that makes sense. To answer your question more directly, the orientation is multiplied by 2 because the scripter wants a point 2m in front of the creature. If they wanted 3 meters, they would multiply by 3. If they wanted 5 meteres behind, they would multiply by -5.

#3
gordonbrown82

gordonbrown82
  • Members
  • 544 messages
ok thanks.