Hello, I’m attempting to move a game object in a horizontal line via vector addition. However, my code (included below) moves the game object diagonally. I am not sure why – shouldn’t adding a v3 to a v3 with the coordinates (1, 0, 0) only change the value of the x value? If you can help me, please let me know!! (Note: this code used to instead add an altered self.dir value, and I moved to this to see if it would fix things. It did not, but the issue is the same.)
-- TODO: WHY WILL THIS NOT GO STRAIGHT AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
function update(self, dt)
local pos = go.get_position()
if self.go_left then
print(pos)
altvector = vmath.vector3(-1,0,0)
pos = pos + (altvector * self.speed * dt)
print(pos)
go.set_position(pos)
self.local_pos = self.local_pos - 1
else
print(pos)
altvector = vmath.vector3(1,0,0)
pos = pos + (altvector * self.speed * dt)
print(pos)
go.set_position(pos)
self.local_pos = self.local_pos + 1
end
if self.local_pos > self.range or self.local_pos < (self.range * -1) then
self.go_left = not self.go_left
update_animation(self)
end
end
[Sample string of code when run:
DEBUG:SCRIPT: vmath.vector3(202, 200, 1)
DEBUG:SCRIPT: vmath.vector3(202, 199.74746704102, 1)
DEBUG:SCRIPT: vmath.vector3(203, 199.74746704102, 1)
DEBUG:SCRIPT: vmath.vector3(203, 199.74533081055, 1)]
[The game object starts at coordinate 200, 200, 1]