Notifications
Clear all
[Closed] myObject.pos += myVector.dir
Oct 21, 2010 10:57 pm
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
Oct 21, 2010 10:57 pm
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
Oct 21, 2010 10:57 pm
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
Oct 21, 2010 10:57 pm
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
)
Oct 21, 2010 10:57 pm
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