Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
Waldemar 337

Moving a position by vector

Recommended Posts

Which is the most efficient way to move the position by a vector ?

 

I don't think that the + operator in SQF is capable of doing it.

The vectorAdd function ( https://community.bistudio.com/wiki/vectorAdd ) sums two vector operands.

I need to apply a vector to a 3D point which is a position.

E.g.

(position player) += delta_vector;
_obj setPos ((position _obj) vectorAdd  delta);

Will this work ?

 

Thank you.

Share this post


Link to post
Share on other sites

Best way to find out if something "will work" is to just try it

 

vectorAdd will add 2 2-element or 3-element arrays as if:

{
	_vector1 set [_forEachIndex, (_vector1 # _forEachIndex) + _x;
} forEach _vector2;

Or in other words, it will add each position in the arrays together. So if that's the behavior you're looking for then yes

 

Also yes because this is specifically what I use when I want to move something relative to it's current position

  • Like 1

Share this post


Link to post
Share on other sites
13 hours ago, Waldemar 337 said:

Which is the most efficient way to move the position by a vector ?

 

I don't think that the + operator in SQF is capable of doing it.

The vectorAdd function ( https://community.bistudio.com/wiki/vectorAdd ) sums two vector operands.

I need to apply a vector to a 3D point which is a position.

E.g.


(position player) += delta_vector;

_obj setPos ((position _obj) vectorAdd  delta);

Will this work ?

 

Thank you.

 

It's confusing, using absolute player position as a relative vector.... What is your goal exactly, between player and object?

Share this post


Link to post
Share on other sites

I wanted to create an object infront of the player.

At the moment I found a simple solution, but I do not know whether it is efficient or not.

_vehPos = (position _caller) vectorAdd ((vectorDir _caller) vectorMultiply (k));

Why is it confusing ? What is the better way ?

Share this post


Link to post
Share on other sites
37 minutes ago, Waldemar 337 said:

I wanted to create an object infront of the player.

So there are several ways you can do this:

player setPos ((getPos player) vectorAdd [0,5,0]);
player setPos (player getPos [5,0]);
player modelToWorld [0,5,0]; //@_foley

All of these are roughly equivalent in effect (no idea about performance), though due to the nature of getPos and setPos to change context over land vs water, some may have weird side effects

  • Like 1

Share this post


Link to post
Share on other sites

×