Can I just query for linear velocity of a body like I query for x and y position or do I have to set up a loop with a getLinearVelocity function?
Thanks
[import]uid: 8192 topic_id: 1849 reply_id: 301849[/import]
Can I just query for linear velocity of a body like I query for x and y position or do I have to set up a loop with a getLinearVelocity function?
Thanks
[import]uid: 8192 topic_id: 1849 reply_id: 301849[/import]
You don’t need a loop, you can just call the function whenever you want the values:
vx, vy = body:getLinearVelocity()
The reason this is a function rather than an attribute (like “body.linearVelocity”) is that it returns TWO values, which are the x-component and y-component of the linear velocity. [import]uid: 3007 topic_id: 1849 reply_id: 5623[/import]
Will there ever be a body.LinearVelocityX and body.LinearVelocityY ? [import]uid: 8486 topic_id: 1849 reply_id: 5627[/import]
To be clear, you get both of those now, just ignore the one you don’t care about 
linearVelocityX, linearVelocityY = body:getLinearVelocity()
There’s no performance advantage to having separate x and y calls, because the Box2D C++ method returns both values in all cases, and also expects both values when setting either of them.
It would be possible to break these up for convenience reasons within Corona, but it would really just be a style change. Are there cases where it would help? [import]uid: 3007 topic_id: 1849 reply_id: 5629[/import]
I would like to be able to set the Y linear without setting the X. That’s probably possible even now, but I don’t know how xD [import]uid: 8486 topic_id: 1849 reply_id: 5632[/import]
@H4ch1 – you could do this:
vx, vy = body:getLinearVelocity()
body:setLinearVelocity( vx, 50 )
…so the x-value stays the same, and only the y-value changes (to 50, in this case). [import]uid: 3007 topic_id: 1849 reply_id: 5642[/import]
Yep, I already do this, I just wanted a 1 variable thing. It’s not essential, obviously
[import]uid: 8486 topic_id: 1849 reply_id: 5644[/import]
I am trying to set the maximum velocity of an object. This is becoming quite a task. It’s easy to check for the velocity as v = (vx^2 + vy^2)^(1/2) but how do you tell it to keep those velocities instead of increasing? [import]uid: 8192 topic_id: 1849 reply_id: 6387[/import]
@amigoni – I don’t think you can literally set the maximum velocity of an object.
In a physical simulation, velocity is derived from force and mass. If you apply more force to a mass, you will always get an increase in velocity:
F = ma
Box2D lets you fake things a bit by setting velocity directly, but setting maximum velocity is probably kind of a pain, since it has no real-world counterpart.
However, you can usually find a way to get approximately what you want by playing with other parameters. For example, if the problem is that objects are accelerating “forever”, you can add friction or damping (both linear and radial) to burn off energy.
For example, the “SimplePool” case uses damping so that the balls slow down and stop rolling after awhile, with a value based on what “looked right” after some testing. It was a pretty weird game without those factors, since everything would bounce around the table indefinitely. [import]uid: 3007 topic_id: 1849 reply_id: 6396[/import]
@evank. Thanks for the quick reply. I understand what you mean. I guess I am trying to use some parts of the physics engine as collisions while not using others for motion. I remember seeing some code for velocity out there that did not use the physics engine. If you know where it is can you point me to it? I will look in the sample files in the meantime.
I am trying to replicate functions that I have used in the past such as:
Move to a point with (x,y) coordinates
move in a certain angle with a certain velocity
accelerate to a point with certain magnitude
accelerate at certain angle with certain magnitude.
[import]uid: 8192 topic_id: 1849 reply_id: 6410[/import]