This is my object which i want to give upward velocity
local myImage = display.newImage( "rose.png" )
myImage.x = 320
myImage.y = 500
myImage.rotation = 0
physics.addBody( myImage, { density=0.1, friction=2.0, bounce=0.0,velocity=-40 } )
Function to give upward velocity
local function test()
myImage:setLinearVelocity(0, -20)
end
test()
The object is not moving upward and this is my physics:
adding Physics
local physics =require("physics")
physics.setGravity(0,0.9)
physics.start()
Your object's linear velocity is being affected by gravity. You can either set the linear velocity every frame with a Runtime enterFrame listener, or you could turn off gravity for your myImage object with:
myImage.gravityScale = 0
After you add the physics body.
尝试将重力的y
值设置为负数。
physics.setGravity(0, -0.98)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.