Notifications
Clear all

[Closed] myObject.pos += myVector.dir

I feel silly for asking, but how does one go about adding a .dir value to a .pos value?

myObject.pos += myVector.dir
4 Replies

The above code works for me, what is the problem exactly?
Assuming myVector is another object and not a vector, of course
Otherwise, if myVector=[0,0,1] or something, then you would say

myObject.pos += myVector

The question is do you want to apply the .dir vector to the object (ie, rotate myObject to match myVector) or do you want to simply add the normalized .dir to the myObject’s .pos.

-Eric

Whoops! That code does work. I didn’t think it would be that simple.
However, Eric poses my next question: How would one rotate the object in the vector direction?
Example WIP code:

(
  --MUST have an object selected
  local randomNum = (random 1 4)
  local rayXcontroller1 = (random 0.0 1.0)
  local rayYcontroller1 = 1 - rayXcontroller1 --get a normalized Y, ignore Z
  local checkRaypost1 = undefined
  --pick a random direction
  	case of
  	(
  		(randomNum == 1): checkRaypost1 = ray $.pos [rayXcontroller1,rayYcontroller1,0]
  		(randomNum == 2): checkRaypost1 = ray $.pos [-rayXcontroller1,rayYcontroller1,0]
  		(randomNum == 3): checkRaypost1 = ray $.pos [rayXcontroller1,-rayYcontroller1,0]
  		(randomNum == 4): checkRaypost1 = ray $.pos [-rayXcontroller1,-rayYcontroller1,0]
  	)
  --add the vector to the object selected, along with some randomness
  $.pos += checkRaypost1.dir*randomNum*randomNum
  )
 eek

I’d go super simple and use angleAxis,

local ang = 30.0
local dir = [random -1.0 1.0, random -1.0 1.0, random -1.0 1.0]


<node>.rotation = angleAxis ang dir