Camera to follow mouse drag
by Giorgio Bertolone · in Torque Game Builder · 02/21/2009 (9:02 am) · 3 replies
Hi guys,
any ideas on how to make the camera follow the mouse drag movement in an inverted way?
(Example: I drag left with mouse and the camera goes right)
Any help is very much appreciated.
Giorgio
any ideas on how to make the camera follow the mouse drag movement in an inverted way?
(Example: I drag left with mouse and the camera goes right)
Any help is very much appreciated.
Giorgio
About the author
#2
02/27/2009 (4:04 am)
Thanks for the tip Simon!
#3
This may help you,
hope it helps
FYI, the above code checks and only moves the camera if the mouse is within 50px of the edge of the window:
this is based on a resolution of 800x600 so can be adjusted accordingly.
Also you can use
to only move if left mouse button is held down.
02/27/2009 (4:54 am)
Hi,This may help you,
function sceneWindow2D::onMouseMove(%this, %modifier, %worldPosition, %clicks)
{
%windowCoordinates = sceneWindow2D.getWindowPoint(%worldPosition);
%x = getWord(%windowCoordinates, 0);
%y = getWord(%windowCoordinates, 1);
%worldX = getWord(%worldPosition, 0);
%worldY = getWord(%worldPosition, 1);
if(%x <= 50 || %x >= 750 || %y <= 50 || %y >= 550)
{
%vec = t2dVectorSub(%worldPosition, cameraHolder.getPosition());
%angle = -mRadToDeg(mATan(getWord(%vec,0),getWord(%vec,1)));
cameraHolder.setLinearVelocityPolar(%angle, -30);
}
else
cameraHolder.setLinearVelocityPolar(cameraHolder.getRotation(), 0);
}This relies on having the camera mounted to another object, (I used a 12x12 transparent image) then in the above code replace the cameraHolder with the name of the transparent object.hope it helps
FYI, the above code checks and only moves the camera if the mouse is within 50px of the edge of the window:
if(%x <= 50 || %x >= 750 || %y <= 50 || %y >= 550)
this is based on a resolution of 800x600 so can be adjusted accordingly.
Also you can use
sceneWindow2D::onMouseDragged(%this, %modifier, %worldPosition, %clicks)
to only move if left mouse button is held down.
Torque 3D Owner Simon Jensen
SwiftThought Games
And then when you start the Drag mount the camera to the invisible object and then unmount it when you release the Drag.