Collision of Bullet with Wall at Same Speed

Hello

I am working on a game where I need collision of Bullet with wall. The bullet should auto rotate when it reflects after collision. I want the speed of bullet to be constant. It should not slow down upon collision.

Also I want proper formula to achieve continuous moment of bullet. Please check the following flash game for
the bullet behavior. I want the same behavior of bullet.

http://www.coolbuddy.com/games/game.asp?gid=971
Thanks
Devon. [import]uid: 40227 topic_id: 29423 reply_id: 329423[/import]

If you set the gravity of the world to 0 by using physics.setGravity(0, 0)
and make the bodies have a bounce value of 1, you should get the behavior that’s in that game. [import]uid: 164950 topic_id: 29423 reply_id: 118397[/import]

Thanks for your help.
Yes, If I set Gravity to zero, then it works perfectly.

But I also need Gravity in my game, there are certain objects in the game which needs gravity.
So I can’t set Gravity to zero.

Can you please suggest alternate solution!!

Thanks!!! [import]uid: 40227 topic_id: 29423 reply_id: 118424[/import]

Try making the bullets kinematic bodies. that way they will not be affected by gravity, so you can keep gravity to affect other dynamic bodies, but the kinematic bullets still receive collision and forces other than gravity. At least that’s what the docs says. I haven’t actually tried it but it should work according to the docs. [import]uid: 164950 topic_id: 29423 reply_id: 118427[/import]

Hello intoitgames,

Thanks for quick reply. Here is what I did.

  • Bullet Body - Kinematic
  • Right Wall - Static
  • Left Wall - Static

But the Kinematic body passes through static body. It is not colliding with it.
So the bullet is not bouncing back.

Thanks!! [import]uid: 40227 topic_id: 29423 reply_id: 118591[/import]

I guess I interpreted the docs wrong. I just had a thought though. What if you made the bullet dynamic, but made its density 0? It would still collide with static bodies but gravity should not have an effect on a body with no mass? [import]uid: 164950 topic_id: 29423 reply_id: 118593[/import]

Hello

I set the density to zero. But the bullet body is still affected by gravity.

Thanks!! [import]uid: 40227 topic_id: 29423 reply_id: 118599[/import]

i had that problem in my game but solved it using gravity (0,0) And then i applied a constant force pulling the object you want to fall down

local function onEnterFrame( event )  
  
 object:applyForce(0, 20)  
  
end  
  
Runtime:addEventListener("enterFrame", onEnterFrame)  

works splendid [import]uid: 134049 topic_id: 29423 reply_id: 118606[/import]

@Anakta

Thanks for your help.

I will try this solution. I will post here if I face any issues!!
My only concern is “Will it slow down performance?” as I have many objects in the plat area.

Thanks!!! [import]uid: 44599 topic_id: 29423 reply_id: 118617[/import]

Depends on how many objects you are planning to have, i have 10 objects thats affected by the constant force and i have no performance drops what so ever. If you do experience performance drops post your code and i might be able to help :slight_smile: [import]uid: 134049 topic_id: 29423 reply_id: 118618[/import]

The problem is resolved now. Corona Build 2012.773 allows you to specify gravityScale property.
So you can control the behavior of physics object according to Gravity.

local brick2 = display.newImageRect( "soda\_can.png", 22, 40) brick2.x = 150 brick2.y = 100 physics.addBody( brick2, { density=3.0, friction=0.5, bounce=0.05 } ) brick2.gravityScale = 0 -- (0 = Cancel Out Gravity Effect, -1=Reverse Gravity) [import]uid: 40227 topic_id: 29423 reply_id: 119011[/import]