Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Physics Bug With Static Object Overlaying Dynamic Object
Started by lofy Feb 20 2019 10:46 AM

8 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

lofy

[GLOBAL: userInfoPane.html]
lofy
  • Enthusiast

  • 75 posts
  • Corona SDK

So I've created a game and I've got almost all the bugs ironed out but one last one persists. I've had it the entire time and don't know what I can do to get rid of it. To understand it you need to understand my game itself. Its a brick breaker game, but instead of a paddle you have a dragon that can be drawn anywhere. What this causes issues with is that the dragon can be drawn around and over the ball. This causes the physics engine to bog down hard trying to calculate where the ball should go. I've added this video as an example. 

 

https://youtu.be/MHsGPWIQH9Q



[TOPIC: post.html]
#2

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,708 posts
  • Corona SDK

I think you'll probably need to help the physics engine out, perhaps move the ball out of the way of the dragon and calculate the effect of the initial collision yourself.

[TOPIC: post.html]
#3

lofy

[GLOBAL: userInfoPane.html]
lofy
  • Enthusiast

  • 75 posts
  • Corona SDK

That was my first instinct as well, I've thought of pausing the physics engine as well. However I'm really running into issues trying to detect the first problem. It's difficult to detect if its normal gameplay or the bug happening. 



[TOPIC: post.html]
#4

horacebury

[GLOBAL: userInfoPane.html]
horacebury
  • Corona Geek

  • 3,059 posts
  • Corona SDK

Make the components of the dragon sensors. When a collision occurs, calculate the angle the ball has with its nearest dragon component and use applyForce() or applyLinearImpulse() to push it away.

 

Don't forget to fire the force/impulse by using a timer - you can't affect the physics world from within the handler of a collision event.

 

Cool looking game.


  • roaminggamer likes this

[TOPIC: post.html]
#5

lofy

[GLOBAL: userInfoPane.html]
lofy
  • Enthusiast

  • 75 posts
  • Corona SDK

This is the exact brilliant response I am looking for! I'm still working on how to calculate the angle but this is the solution that should solve the physics problem. 



[TOPIC: post.html]
#6

horacebury

[GLOBAL: userInfoPane.html]
horacebury
  • Corona Geek

  • 3,059 posts
  • Corona SDK

https://github.com/HoraceBury/MathLib



[TOPIC: post.html]
#7

lofy

[GLOBAL: userInfoPane.html]
lofy
  • Enthusiast

  • 75 posts
  • Corona SDK

I case someone comes across this in the future. This solved the issue. 

 

A few notes: 

1.) Applying a force without a timer is now a possibility with Corona it seems like the physics was updated at sometime so there isn't the need for a timer anymore, and with the timer it was causing issues. 

 

2.) I had to set a flag so that an additional counter force wouldn't be applied until the collision had ended. I set these flags by using phase == began and phase == ended sections within the collision listener. 

 

3.) Figuring out which side the ball should come off the dragon took a little fancy math. I solved it by getting the two normal angles to the direction of the dragon and comparing balls angle to the physical distance between the ball angle and the two normal angles to figure out which angle was the closest. 



[TOPIC: post.html]
#8

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 582 posts
  • Corona SDK

I'm not sure that your first point, i.e. the physics library being updated, was actually not done.

 

Corona uses Box2D and I don't think it has been updated for almost a year. Not sure which version of it Corona is using either. I am also not aware of any problems with applying force to objects to begin with.

It is likely that you simply ran into some issues related to it, such as trying to apply force object to an object before it had actually been created by the physics engine, or maybe you were fighting the physics engine itself.



[TOPIC: post.html]
#9

lofy

[GLOBAL: userInfoPane.html]
lofy
  • Enthusiast

  • 75 posts
  • Corona SDK

I might have been mistaken but I thought you used to be that you had use a timer when apply physics changes aka: 

 

 

 

Don't forget to fire the force/impulse by using a timer - you can't affect the physics world from within the handler of a collision event.

 

I could have been mistaken, either way you don't need to use the timer to get it to work. 




[topic_controls]
[/topic_controls]