Mouse movement and collision
by Steven Hine · in Torque Game Builder · 06/14/2007 (8:04 pm) · 1 replies
Here's the problem I'm having:
I have the mouse moving my paddle back and forth on the screen. But when the paddle hits its world limits it bounces between the mouse position and its limit point. The only way I could fix this is to have the mouse check its X position and fix it if it was outside the world limits of the paddle.
function sceneWindow2D::mouseMovePaddle(%this, %mod, %worldPosition)
{
%movement = %this.getMousePosition();
%mouseX = getWord(%movement, 0);
//clamp to boundries
if(%mouseX < -40)
%mouseX = -40;
if(%mouseX > 40)
%mouseX = 40;
$pPaddle.setPositionX(%mouseX);
%this.setMousePosition($pPaddle.getPosition());
Canvas.hideCursor();
$lastMousePos = $pPaddle.getPosition();
}
I tried to use $pPaddle.minX = getWord($pPaddle.getWorldLimit(), 1) instead of the -40, but I didn't work. It was only when I hard coded the limit that it worked.
Any ideas would be great. I want to make levels with out having to hard code all the boundries...
I have the mouse moving my paddle back and forth on the screen. But when the paddle hits its world limits it bounces between the mouse position and its limit point. The only way I could fix this is to have the mouse check its X position and fix it if it was outside the world limits of the paddle.
function sceneWindow2D::mouseMovePaddle(%this, %mod, %worldPosition)
{
%movement = %this.getMousePosition();
%mouseX = getWord(%movement, 0);
//clamp to boundries
if(%mouseX < -40)
%mouseX = -40;
if(%mouseX > 40)
%mouseX = 40;
$pPaddle.setPositionX(%mouseX);
%this.setMousePosition($pPaddle.getPosition());
Canvas.hideCursor();
$lastMousePos = $pPaddle.getPosition();
}
I tried to use $pPaddle.minX = getWord($pPaddle.getWorldLimit(), 1) instead of the -40, but I didn't work. It was only when I hard coded the limit that it worked.
Any ideas would be great. I want to make levels with out having to hard code all the boundries...
About the author
Torque Owner Steven Hine
function sceneWindow2D::mouseMovePaddle(%this, %mod, %worldPosition)
{
%movement = %this.getMousePosition();
%mouseX = getWord(%movement, 0);
//clamp to boundries
if(%mouseX < $pPaddle.minX + $pPaddle.getWidth()/2)
%mouseX = $pPaddle.minX + $pPaddle.getWidth()/2;
echo(%mouseX);
if(%mouseX > $pPaddle.maxX - $pPaddle.getWidth()/2)
%mouseX = $pPaddle.maxX - $pPaddle.getWidth()/2;
echo(%mouseX);
$pPaddle.setPositionX(%mouseX);
%this.setMousePosition($pPaddle.getPosition());
$lastMousePos = $pPaddle.getPosition();
}
The trick was to check that the center point wasno reaching the worldlimit. When it did the image was hanging over, because it was forced over. by using the width/2, you can change the image and it will still work.
Steve