Set Linear Velocity Polar maxed out at 125?
by Andrew Deters · in Torque 2D Beginner · 03/07/2015 (4:02 am) · 4 replies
function ObjectClass::OnTimer(%this)
{
//used to speed up and regulate speed of object
%angle = getword(%this.getLinearVelocityPolar(),0);
%speed = getword(%this.getLinearVelocityPolar(),1);
%maxSpeed = 200;
// slows the object
if (%speed > %maxSpeed)
{
%this.setLinearVelocityPolar(%angle, %speed-4);
}
// speeds up the object
else if (%speed < %maxSpeed)
{
%this.setLinearVelocityPolar(%angle, %speed+4);
}
}I have this code to accelerate an object to a max speed and keep it there. I am having a problem where the %speed always maxes out at 125 no mater what I have tried. The code works as intended if the %maxSpeed is lower than 125, but thats much slower than what I would like. Does anyone know why this is happening, or how to increase the limit if there is one?
#2
03/10/2015 (8:39 am)
I don't suppose there is one universal setting that I can change? Or is it that I need to scale all objets in the game manually? I am sure its the latter if I understand you right.
#3
03/10/2015 (9:56 am)
No, there isn't a universal scaling factor for scene objects. The default camera view size is 100 meters x 75 meters and the default size for an object is 1 meter x 1 meter. After that, it is up to you to customize it to your liking, keeping in mind the following:Quote:"Box2D works with floating point numbers and tolerances have to be used to make Box2D perform well. These tolerances have been tuned to work well with meters-kilogram-second (MKS) units. In particular, Box2D has been tuned to work well with moving shapes between 0.1 and 10 meters. So this means objects between soup cans and buses in size should work well. Static shapes may be up to 50 meters long without trouble."
#4
Thanks for everything
03/13/2015 (12:41 pm)
After scaling down all my sprits, positions, and the camera I now can achieve the speeds I want. Everything works and looks exactly as it did before with one exception. I have a ball that should move at a constant speed bounce, and has a particle emitter attached with a revolute joint. Before the changes everything was fine, but now the ball acts as if it's constantly colliding with the emitter. It slows down over time and slides along instead of bouncing. I have double checked if I changed the emitters physics setting by mistake, but I see nothing wrong. Any ideas what might have changed? Or any recommendations on how to set up the emitter and joint? The ball moves fine when nothing is attached. Thanks for everything
Torque Owner Richard Ranft
Roostertail Games
For instance - we noticed it when we tried to scale a scene the way we used to, with T2D's old coordinate system. Blackjack, the table was like 1200 meters wide and moving a card across it in 1.2 seconds was not working, so we scaled the scene so that the table was the expected 2 meters wide and the card now moved at a speed that Box2D was willing to allow.
So, try scaling everything down by a factor of 10 and modify the camera to keep your visible scale?