I’m trying to draw a line (beams) starting from a fixed location to the coordinates of a mouse click. After trying several methods, I see that scaling a sprite from the location towards the coordinate is probably the easiest way. So I achieve this via:
local beamInstance = factory.create('/beamInstance#beamFactory', vmath.vector3(640, 65, 0)) -- Stretch beam out to mouse click location on Y axis local beamPosition = go.get(beamInstance, 'position') local distance = beamPosition.y - action.y go.set(beamInstance, 'scale.y', distance) go.set(beamInstance, 'position.y', beamPosition.y - distance / 2) -- offset
The end result looks like this:
However when I rotate this beam towards the mouse click, the origin point of the beam also moves.
angle = math.atan2(action.x - beamPosition.x, beamPosition.y - action.y) go.set(beamInstance, 'rotation', vmath.quat_rotation_z(angle))
Resulting in this:
What would be the best way to achieve rotation in this case while maintaining a fixed origin position?
I’m attaching the playground I created for this example in case anyone ones to load it up.
BeamTest.zip (629.2 KB)