I’m firing a bullet and when it strikes a wall it bounces off at a 90 degree angle instead of at the proper angle. But when I fire a second bullet and it strikes the first bullet, it does bounce off the other bullet at the proper angle.
How do I make the walls behave like the bullets as it relates to ricochets?
Here’s a portion of my code when I fire the bullet, then when the bullet collides with a wall, and then it ricochets off the wall:
function fireBullet(source, angle) bullet = display.newImage("bullet.png") bullet.myName="bullet" bullet.x, bullet.y, bullet.rotation = source.x, source.y, angle physics.addBody( bullet, "dynamic",{density=.0, bounce=1, friction=1,radius=15}) bullet.isFixedRotation = true local direction = rotateTo( {x=2,y=0}, angle ) bullet:applyForce( direction.x, direction.y, bullet.x, bullet.y ) bullet:addEventListener( "collision", bulletHit) end local locationX local locationY function bulletHit(event,angle) locationX = event.target.x locationY = event.target.y print("bullet hit count is ",count) if ( event.phase == "began" ) then timer.performWithDelay(1,function(other,target,angle) return ricochet(self,event)end) end end function ricochet(self,event ) event.target:applyForce(( event.target.x-event.x), (event.target.y-event.y), event.target.x,event.target.y ) bullet.isBullet = true print("bullet angle is ", bullet.direction) bullet.rotation= bullet.rotation\*2 print("this is bullet rotation angle after it should have changed- ",bullet.rotation) count=count+1 return true end