[Resolved] Determine an object's velocity with physics?

Hi XD I’m quite new to Corona and am trying out a lot of things atm.
I was wondering, after applying physics to a body like this

[code]local physics = require(“physics”)
physics.start()
physics.setGravity(0, 0.9)

local background = display.newImage(“bkg_clouds.png”)

local ball = display.newImage(“ball.png”)
ball.x = 100
ball.y = 100
physics.addBody(ball, {bounce = 0.5})

local ground = display.newImage(“ground.png”)
ground.y = display.contentHeight - ground.stageHeight/2
physics.addBody(ground, “static”, {bounce = 0.2})[/code]

Is it possible to determine whether the ball is still falling or not?

Or rather, is there a way to figure out the ball’s speed like this or do I have to make some changes to the code?

Would be awesome if somebody could help me out, thanks :3 [import]uid: 191248 topic_id: 33018 reply_id: 333018[/import]

Hi @dianasuwamoto,
Welcome to Corona. Your code looks good so far. The command you’re looking for is this:

local vx,vy = ball:getLinearVelocity()

This will, of course, give you “vx” and “vy” which are the linear velocities at any given time. You can use this information to determine if the ball is falling (“vy” would be positive). Printing the values to the Terminal will show you the approximate values you’re dealing with: very small decimal values near to 0 indicate the ball is almost stopped, but you can’t assume that they’ll ever equal 0 exactly unless you explicitly set them using ball:setLinearVelocity( 0,0 ). You might get values around 0.01 or less… so small that the ball might appear stopped, but by measure of the physics engine, it’s still moving. :slight_smile:

Any other questions, don’t hesitate to ask.

Brent Sorrentino
[import]uid: 9747 topic_id: 33018 reply_id: 131088[/import]

Hi @dianasuwamoto,
Welcome to Corona. Your code looks good so far. The command you’re looking for is this:

local vx,vy = ball:getLinearVelocity()

This will, of course, give you “vx” and “vy” which are the linear velocities at any given time. You can use this information to determine if the ball is falling (“vy” would be positive). Printing the values to the Terminal will show you the approximate values you’re dealing with: very small decimal values near to 0 indicate the ball is almost stopped, but you can’t assume that they’ll ever equal 0 exactly unless you explicitly set them using ball:setLinearVelocity( 0,0 ). You might get values around 0.01 or less… so small that the ball might appear stopped, but by measure of the physics engine, it’s still moving. :slight_smile:

Any other questions, don’t hesitate to ask.

Brent Sorrentino
[import]uid: 9747 topic_id: 33018 reply_id: 131088[/import]

That’s exactly what I was looking for! Thank you so much :3 [import]uid: 191248 topic_id: 33018 reply_id: 131198[/import]

That’s exactly what I was looking for! Thank you so much :3 [import]uid: 191248 topic_id: 33018 reply_id: 131198[/import]