Getting Started Guide Spaceship not flying in the correct direction
by zackl · in Torque 2D Beginner · 02/02/2014 (12:01 am) · 8 replies
I have recently come back here after being gone awhile and I started off with the getting started tutorial. I have completed the tutorial but, when I accelerate the spaceship it goes in an incorrect direction. I have double checked the code to see if I had misspelled something I even tried the download sample and got the same thing. When the game first starts and the ship is pointing up or angle 0 and I press "w" the ship flies to the right. When the ship is pointing right or angle 90 it flies down.If it is pointing down or 180degs it flies left. Pointing left it flies down. I don't know what is going on and I was wondering if anyone had run into this before. Thanks.
#2
Until T2D 3.0 is officially pushed into the master branch - I didn't want to update the tutorial yet. To fix it, change the accelerate method to this:
02/02/2014 (2:57 am)
The first question would be to know if you are using a binary download, master branch or development branch compile? It sounds like a development branch issue, as Simon pointed out we did a change which will go live with T2D 3.0.Until T2D 3.0 is officially pushed into the master branch - I didn't want to update the tutorial yet. To fix it, change the accelerate method to this:
function PlayerShip::accelerate(%this)
{
//Get the angle of our spaceship. When the ship is pointing upwards, its Angle is 90.
%adjustedAngle = %this.Angle + 90;
//When used as a math operand, % refers to modulo (or modulus) operator
//This function can be read as %adjusted angle = %adjustedAngle % 360;
%adjustedAngle %= 360;
//If we are thrusting, shorten our vector
if(%this.isThrusting)
{
//Calculate a direction from an Angle and Magnitude
%ThrustVector= Vector2Direction(%adjustedAngle,35);
}
else
{
%ThrustVector = Vector2Direction(%adjustedAngle,95);
//We temporarily remove the Damping of Linear Velocity to allow full power!
%this.setLinearDamping(0.0);
//We temporarily increase the Damping of Angular velocity so that the ship turns slower when at full thrust
%this.setAngularDamping(2.0);
}
//Adding our position to the ThrustVector determines the strength of our thrust
%MywordX = %this.Position.x + %ThrustVector.x;
%MywordY = %this.Position.y + %ThrustVector.y;
//applyLinearImpulse pushes on our spaceship, using %ThrustVector as the impulse vector.
//The second parameter is the point in the ship's collision shape used to apply the thrust
%this.applyLinearImpulse(%ThrustVector, "0 0");
//We are now thrusting, we will set this to false when we release the 'w' key
%this.isThrusting = true;
//We create a schedule to repeat this thrust every 100 milliseconds
%this.thrustschedule = %this.schedule(100,accelerate);
}
#3
//Adding our position to the ThrustVector determines the strength of our thrust
28. %MywordX = %this.Position.x + %ThrustVector.x;
29. %MywordY = %this.Position.y + %ThrustVector.y;
As far as the version I am using I just followed the tutorial so I bet you are probably right and I am using the Development branch. Should I be using the Master branch? I am new to all of the open source stuff and trying to get used to github and the proper procedures. Thanks for all of your help Mike. Thanks to you as well Simon for your quick response. I have always thought this community is definitely worth their weight in gold.
02/02/2014 (9:34 am)
Hey that did it. Thanks. I tried to add the +90 to %this.angle but had limited success. Was that all that was different? Also their is a set variables created but, I can't see how they are being used. //Adding our position to the ThrustVector determines the strength of our thrust
28. %MywordX = %this.Position.x + %ThrustVector.x;
29. %MywordY = %this.Position.y + %ThrustVector.y;
As far as the version I am using I just followed the tutorial so I bet you are probably right and I am using the Development branch. Should I be using the Master branch? I am new to all of the open source stuff and trying to get used to github and the proper procedures. Thanks for all of your help Mike. Thanks to you as well Simon for your quick response. I have always thought this community is definitely worth their weight in gold.
#4
//make sure that the angle is always between 0 and 360 degrees
if(%adjustedAngle<0)%adjustedAngle *= -1;
else if(%adjustedAngle>0)%adjustedAngle = 360-%adjustedAngle;
now it works fine. Any way to post this to the document for future new users?
02/02/2014 (9:47 am)
Oh ok you also removed://make sure that the angle is always between 0 and 360 degrees
if(%adjustedAngle<0)%adjustedAngle *= -1;
else if(%adjustedAngle>0)%adjustedAngle = 360-%adjustedAngle;
now it works fine. Any way to post this to the document for future new users?
#5
It must be from an earlier version where I didn't use applyLinearImpulse.
Branches
Choosing which branch you want to work with depends on your needs.
The master branch can be considered stable and is only updated every few months.
The development branch is the one which receives all the fixes and pull requests, making it potentially unstable and in need of testing by the community. It might contain improvements, bug fixes and new features that are not yet found in the master branch.
Every few months, when the development branch is judged to be stable enough, it will become the new master branch for the latest version of the engine. This is what will happen when T2D 3.0 comes out.
02/02/2014 (9:57 am)
After quickly verifying the code, you are correct, the following does nothing, as %MywordX and %MywordY aren't used anywhere : %MywordX = %this.Position.x + %ThrustVector.x; %MywordY = %this.Position.y + %ThrustVector.y;
It must be from an earlier version where I didn't use applyLinearImpulse.
Branches
Choosing which branch you want to work with depends on your needs.
The master branch can be considered stable and is only updated every few months.
The development branch is the one which receives all the fixes and pull requests, making it potentially unstable and in need of testing by the community. It might contain improvements, bug fixes and new features that are not yet found in the master branch.
Every few months, when the development branch is judged to be stable enough, it will become the new master branch for the latest version of the engine. This is what will happen when T2D 3.0 comes out.
#6
02/02/2014 (10:23 am)
After checking I think I am using the Master branch. I am not really sure how to check but, when I sign in to github.com and compare mine with the master it says they are the same also when I used gitbash it had master next to the branch I was in until I created a new dev. branch in gitbash and then pulled it. I really just followed the instructions and went from there.
#8
02/02/2014 (11:30 am)
I'd recommend SourceTree. It's free to use for any purpose and a really good GUI Git client.
Associate Simon Love
From what I know, there was a change to make angles and coordinates more consistent; I wrote the guide wayyy before that change and I remember having to be creative with the math to make it behave like I wanted.
I suspect this pull request to be the culprit.
I do not have the time to dig back into it nor do I have access to the wiki at this point (Having left the committee in September 2013) but if you find the fix, I suggest letting us know on this post!