Stop a ball
by Harrison Brock · in Torque Game Builder · 08/21/2006 (6:58 pm) · 3 replies
I have a ball and two pad. When the game start the ball is on pad_1 when the user click on the ball it move to pad_2 and it should stop but the ball just move back to the left.
here is the code:
$yVelocity = 20;
$xVelocity = 25;
$ballAngularVelocity = 60;
function ball::onAdd(%this)
{
%this.setUseMouseEvents(true);
}
function ball::onMouseDown(%this, %modifier, %worldPosition, %mouseClicks)
{
%this.setLinearVelocity($xVelocity,$yVelocity);
%this.setAngularVelocity($ballAngularVelocity);
%this.setForwardMovementOnly(true);
}
I know that I need to set $xVelocity,$yVelocity, and $ballAngularVelocity to 0 when the ball hit the pad. How should I do this.
here is the code:
$yVelocity = 20;
$xVelocity = 25;
$ballAngularVelocity = 60;
function ball::onAdd(%this)
{
%this.setUseMouseEvents(true);
}
function ball::onMouseDown(%this, %modifier, %worldPosition, %mouseClicks)
{
%this.setLinearVelocity($xVelocity,$yVelocity);
%this.setAngularVelocity($ballAngularVelocity);
%this.setForwardMovementOnly(true);
}
I know that I need to set $xVelocity,$yVelocity, and $ballAngularVelocity to 0 when the ball hit the pad. How should I do this.
Torque Owner Shane B.
function pad::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal,%contactCount, %contacts ) { if (%dstObj.class$="balls") { %dstObj.setLinearVelocity(0,0); %dstObj.setAngularVelocity(0); } }