Problem with mouse controlling
by pippop · in Torque Developer Network · 08/21/2012 (3:23 am) · 1 replies
Hi,
i want control my player with mouse. So i followed some tutorial and i write this code:
Thank you!
Sorry for my bad English isn't my native speaking language...
i want control my player with mouse. So i followed some tutorial and i write this code:
function SceneWindow2D::mouseMoveShip(%this, %mod, %worldPosition)
{
%movement = t2dvectorsub(%worldPosition, $lastMousePos);
//Set the starting position here
%playerPosition = $Player.getPosition();
%mousePosition = sceneWindow2D.getMousePosition();
//%xMouse = getWord(%mousePosition, 0);
//%yMouse = getWord(%mousePosition, 1);
%Angle = t2dAngletoPoint(%playerPosition, %mousePosition);
// this
// $player.setLinearVelocityPolar(%Angle, 10);
// or this (i had the same result)
// $player.moveTo(%mousePosition,5,false,false, true,0.0);
$lastMousePos = $player.getPosition();
}
function SceneWindow2D::onMouseDown(%this, %mod, %worldPosition, %mouseClicks)
{
%this.mouseMoveShip(%mod, %worldPosition);
}In this way, every time i click, the player moves toward the mouse pointer of a little step. It's nice but i want a little different behaviour. I want that the player moves continuously towards the mouse pointer when the mouse button it's down and stops only if i release the button (no drag, it's different!).Thank you!
Sorry for my bad English isn't my native speaking language...
pippop