redrawing an object
by MichaelDom · in Torque Game Engine · 09/07/2010 (3:00 pm) · 4 replies
I have a catapult that launches objects when the player clicks and drags his mouse; the objects speed and angle are based on how far the player dragged the catapult. However, I can't figure out how to get it to reset to its original position onMouseRelease.
Also, I would like to set limits regarding how far in a given direction the catapult can be dragged.
I know these questions are basic and I'm sure someone knows the answer.
Michael
PS: TorqueScript solutions are preferred.
Also, I would like to set limits regarding how far in a given direction the catapult can be dragged.
I know these questions are basic and I'm sure someone knows the answer.
Michael
PS: TorqueScript solutions are preferred.
#2
09/09/2010 (2:03 pm)
Here's some code to look at and disregard the lat comment (if it were true I wouldn't be asking lol). Thanks again.function playerTouchClass::onTimer(%this)
{
if (%this.released)
{
%currentSpeed = %this.getLinearVelocity();
%adjustedSpeed = t2dVectorAdd(%currentSpeed, $gravity);
%this.setLinearVelocity(%adjustedSpeed);
}
}
function backgroundClass::onMouseDown(%this, %modifier, %worldPosition, %clicks)
{
//echo("touch works");
// draw the caatapult
// left side
playerTouch.released = false;
playerTouch.setLinearVelocity(0, 0);
playerTouch.setPosition(%worldPosition);
%leftVector = t2dVectorSub(%worldPosition, leftPoint.getPosition());
%leftVectorScaled = t2dVectorScale(%leftVector, 0.5);
leftSpring.setPosition(t2dVectorAdd(leftPoint.getPosition(), %leftVectorScaled));
%rotationAngleLeft = mRadToDeg(mATan(getWord(%leftVector, 1), getWord(%leftVector, 0))) + 90;
leftSpring.setRotation(%rotationAngleLeft);
leftSpring.setSizeY(t2dVectorLength(%leftVector));
// right side
%rightVector = t2dVectorSub(%worldPosition, rightPoint.getPosition());
%rightVectorScaled = t2dVectorScale(%rightVector, 0.5);
rightSpring.setPosition(t2dVectorAdd(rightPoint.getPosition(), %rightVectorScaled));
%rotationAngleRight = mRadToDeg(mATan(getWord(%rightVector, 1), getWord(%rightVector, 0))) + 90;
rightSpring.setRotation(%rotationAngleRight);
rightSpring.setSizeY(t2dVectorLength(%rightVector));
}
function backgroundClass::onMouseDragged(%this, %modifier, %worldPosition, %clicks)
{
//echo("touch works");
// draw the catapult
// left side
playerTouch.setPosition(%worldPosition);
%leftVector = t2dVectorSub(%worldPosition, leftPoint.getPosition());
%leftVectorScaled = t2dVectorScale(%leftVector, 0.5);
leftSpring.setPosition(t2dVectorAdd(leftPoint.getPosition(), %leftVectorScaled));
%rotationAngleLeft = mRadToDeg(mATan(getWord(%leftVector, 1), getWord(%leftVector, 0))) + 90;
leftSpring.setRotation(%rotationAngleLeft);
leftSpring.setSizeY(t2dVectorLength(%leftVector));
// right side
%rightVector = t2dVectorSub(%worldPosition, rightPoint.getPosition());
%rightVectorScaled = t2dVectorScale(%rightVector, 0.5);
rightSpring.setPosition(t2dVectorAdd(rightPoint.getPosition(), %rightVectorScaled));
%rotationAngleRight = mRadToDeg(mATan(getWord(%rightVector, 1), getWord(%rightVector, 0))) + 90;
rightSpring.setRotation(%rotationAngleRight);
rightSpring.setSizeY(t2dVectorLength(%rightVector));
}
function backgroundClass::onMouseUp(%this, %modifier, %worldPosition, %clicks)
{
// fire the object
playerTouch.released = true;
// first find the midpoint
%midvector = t2dVectorSub(leftPoint.getPosition(), rightPoint.getPosition());
%midPoint = t2dVectorAdd(rightPoint.getPosition(), t2dVectorScale(%midVector, 0.5));
%aimVector = t2dVectorSub(%midpoint, playerTouch.getPosition());
%aimVector = t2dVectorScale(%aimVector, 2);
playertouch.setLinearVelocity(%aimVector);
// attempts to reset the catapults position
}
#3
09/09/2010 (2:24 pm)
That script does not look like anything i know of from TGE. I am guessing TGB? If so i think you might get better help over in TGB's forums.
#4
09/09/2010 (2:29 pm)
Hmm ok not sure where the distinction between the two really is but I'll go post this there as well. Thanks for your help.
Torque Owner Wesley Hopson
Default Studio Name
If so then i think i will just make a wild leap at what the problem might be here, i am probably way off the mark but hey common problems are common for a reason. TGE sometimes has oddities with it's animations. Non cyclic animations remain in there play state after they are done playing so in order to be replayed they need to be told to stop unfortunatly
%thing.stopThread(0);
%thing.playthread(0, "danceAway");
Sadly that won't work, because there is some latency in stopping it so you need to schedule the stop to occur some time after the thread has finished or schedule the playthread to a short while after you stop it.
Of course without being able to see just what exactly you are doing i cannot say wheter that helps or not but might be worth double checking to see if it could be the problem.