Changing Velocity at a Specific Screen Position
by Malcolm Owen · in Torque Game Builder · 03/13/2007 (4:04 pm) · 8 replies
So, yeah, I'm a goddamned idiot. And I spent about 3 hours trying to work this out, and failed. Now, to admit defeat and ask you lot...
Short version - I have an enemy ship descending at a Y velocity of 1 (yes, so slow, but I have reasoning, which will take too long to explain and I will contradict myself twice at least). However, when it reaches a specific Y... Level... Thing... (Y Row? Y Line? Can't think of the name), I want it to update the speed of said enemy from 1 to something faster, like 45.
Anyway, here's the code that I've got to thus far.
function enemyShip::updateMovement(%this)
{
if ( %this.getPositionY() <= 0 ) //Game area is from -50 to +50 on Y co-ords. 0 would be centre of screen
{
%this.setLinearVelocityY(45); //Change the Enemy's Speed
}
}
Anything that I'm doing wrong here? Obviously I am, but I just can't see it at all. Any help would be fantastic...
Short version - I have an enemy ship descending at a Y velocity of 1 (yes, so slow, but I have reasoning, which will take too long to explain and I will contradict myself twice at least). However, when it reaches a specific Y... Level... Thing... (Y Row? Y Line? Can't think of the name), I want it to update the speed of said enemy from 1 to something faster, like 45.
Anyway, here's the code that I've got to thus far.
function enemyShip::updateMovement(%this)
{
if ( %this.getPositionY() <= 0 ) //Game area is from -50 to +50 on Y co-ords. 0 would be centre of screen
{
%this.setLinearVelocityY(45); //Change the Enemy's Speed
}
}
Anything that I'm doing wrong here? Obviously I am, but I just can't see it at all. Any help would be fantastic...
#2
03/13/2007 (4:28 pm)
A positive Y velocity would send the object DOWN the screen ... aside from that, looks like everything should work ... are you getting any errors/warnings in the console about not being able to find things?
#3
And I've changed that < to a >. It's still not working. The ship(s) is(are) still going a death-march down the screen with no speeding up at all.
No errors coming up except for some things about particles, but they shouldn't cause this problem.
I'm now starting to think that the function itself might not be called whilst running...
03/13/2007 (4:41 pm)
Yes, the ship is flying down the screen, and I should have said that. I apologise. And I've changed that < to a >. It's still not working. The ship(s) is(are) still going a death-march down the screen with no speeding up at all.
No errors coming up except for some things about particles, but they shouldn't cause this problem.
I'm now starting to think that the function itself might not be called whilst running...
#4
function enemyShip::updateMovement(%this)
{
if ( %this.getPositionY() >= 0 ) //Game area is from -50 to +50 on Y co-ords. 0 would be centre of screen
{
%this.setLinearVelocityY(45); //Change the Enemy's Speed
}
echo("ShipNum:" @ %this @ " YPos:" @ %this.getPositionY() @ " YVel:" @ %this.getLinearVelocityY());
}
03/13/2007 (5:53 pm)
Yes, if you don't notice any speedup, probably updateMovement is not being called at all. As you already might aware, there's this function called echo which you could use to figure if the function is being called and the values of the variables you're interested in. It would look something like this:function enemyShip::updateMovement(%this)
{
if ( %this.getPositionY() >= 0 ) //Game area is from -50 to +50 on Y co-ords. 0 would be centre of screen
{
%this.setLinearVelocityY(45); //Change the Enemy's Speed
}
echo("ShipNum:" @ %this @ " YPos:" @ %this.getPositionY() @ " YVel:" @ %this.getLinearVelocityY());
}
#5
03/13/2007 (6:55 pm)
@Malcolm, I would assume that updateMovement would be called in either an onTimer or an onUpdateScene callback -- make sure that it is ... ;)
#6
I also now feel really dumb.
03/14/2007 (3:32 pm)
Thanks for the help. Used the onTimer method, and works like a charm. I also now feel really dumb.
#7
03/14/2007 (3:45 pm)
@Malcolm, why? You think we haven't done that before? ... ;)
#8
03/14/2007 (5:25 pm)
Glad you had some great help in getting the issue fixed... also like David said we've all done many things that could be classified as "dumb", comes with the territory of game programming/scripting so don't feel to bad :) An alternate way to accomplish this would be using a trigger.
Torque Owner Nicolas Olhaberry
If that's the case, the "if" line is wrong and it should be "if ( %this.getPositionY() >= 0 )" since values in the Y axis grow downward.