Rotation and physics at same time

Hi, i got a question

I make a top down shooter game, but i got problem

I must use rotation whole time for player, but then collision is buggy

Does there any alternative for player.rotation direct use which can be used same time with physics

At this moment, i use analog joystick for player rotation

player.rotation = moves:getAngle()

any ideas?

P.S. Sorry for bad english

Give us details.  How is collision buggy?

Answer these questions:

  • What do you see / what is happening?
  • What do you expect to see or have happen?

Saying something is buggy without explaining what you mean doesn’t help us to help you.  We need to understand what you think is wrong and why you think it is wrong.

Simply rotating an object should not affect physics performance otherwise no action games would work in Corona.  So, something else is happening.  However, we need to have a better idea of what you are experiencing.

PS - Describe the movement mechanic of your player.  If you cannot, tell us a game or two that has a similarly moving player or enemy.

Well, when collision is made, rotation should not be changed. If I disable rotation everything works fine

https://docs.coronalabs.com/guide/physics/collisionDetection/index.html

Currently, the Box2D physics engine is liable to crash during a collision if Corona code attempts to modify objects still involved in the collision. This is because Box2D is still working out the iterated mathematics on these objects. However, your collision handler may set a flag or include a time delay via timer.performWithDelay() so that the action can occur in the next application cycle or later.

Complete removal of object(s) via display.remove() or object:removeSelf() can be executed during the same collision event time step, but the following APIs and methods can not be called during a collision event:

I will explain what I meant when said buggy

 Collision between player and wall[1]

-If collision angle is 90, player will enter the wall for 1/5 of size

-If collision angle is less than 90, and more than 45, collision will be made 50px in front of wall

-If collision angle is less than 45, collision will go smooth

Thanks for helping :slight_smile:

  1. You may have missed my post-script:

Please give me at least two game examples that have the same or similar player movement. I need the names of the games and/or youtube links of them in action.

  1. Sounds like you have a rectangular body and not a formfitting shape or a circle.

  2. Turn on hybrid draw mode to see the shape of your body and how it interacts with other bodies:

https://docs.coronalabs.com/daily/api/library/physics/setDrawMode.html

  1. Yes, I understand all that about not changing the physics state during a collision, but there is no reason to do so.  You can handle any updates you need one frame later via a timer with a short period (1 ms will do)
  1. This is the nearest i find

https://www.youtube.com/watch?v=3DDWXCc21y0

i have a similar joystick and i get his angle, then:

player:setLinearVelocity( math.sin(math.rad(moves:getAngle())) \* 400, - math.cos(math.rad(moves:getAngle())) \* 400 )
  1. Player is ciricle, it’s reason why i think it will work

  2. hybrid show that player is rect?

    local player = display.newCircle(objects, display.contentWidth/2 + 200, display.contentHeight/2 + 200, 50)

  3. Already check that, no effect

Thanks for fast reply!

That is a 3D game… so super helpful in this discussion.

However, I get the thrust of it. You want to use a joystick to move a player.  

I think you can solve most of your issues by simply  using a circular body.

https://docs.coronalabs.com/daily/api/library/physics/addBody.html

https://docs.coronalabs.com/daily/api/library/physics/addBody.html#circular-body

I don’t know what this meant:

  1. Already check that, no effect

Is this the basic movement you’re talking about?

https://www.youtube.com/watch?v=ShyC11K2te8&feature=youtu.be

If so, SSK2 (lite and PRO)has all the features you need to:

  • handle input
  • set up collisions
  • etc.

It also comes with dozens of samples to help you get rolling.

Hi, thanks a lot, circular body solve a problem with collision when they dont even touching, but player still sometimes go in the wall

For now, i will disable rotating of player.

I’m not sure how much I’m understanding the problem but here are a few suggestions:

  1. Make sure you are rotating the physics objects using physics.  If not, you might be rotating the display object and not the physics object, thus decoupling the display and physics worlds.  This is a common error.  The display object will look fine but the physics will be strange.  Instead of using object.rotation to rotate the physics object, use object.applyAngularImpulse or object.angularVelocity.

  2. Try making the object a bullet.  This forces object to be tracked every frame and is processor intensive but might help if the problem is that your object is moving slightly faster than the calculations.

[lua]

object.isBullet = true

[/lua]

Give us details.  How is collision buggy?

Answer these questions:

  • What do you see / what is happening?
  • What do you expect to see or have happen?

Saying something is buggy without explaining what you mean doesn’t help us to help you.  We need to understand what you think is wrong and why you think it is wrong.

Simply rotating an object should not affect physics performance otherwise no action games would work in Corona.  So, something else is happening.  However, we need to have a better idea of what you are experiencing.

PS - Describe the movement mechanic of your player.  If you cannot, tell us a game or two that has a similarly moving player or enemy.

Well, when collision is made, rotation should not be changed. If I disable rotation everything works fine

https://docs.coronalabs.com/guide/physics/collisionDetection/index.html

Currently, the Box2D physics engine is liable to crash during a collision if Corona code attempts to modify objects still involved in the collision. This is because Box2D is still working out the iterated mathematics on these objects. However, your collision handler may set a flag or include a time delay via timer.performWithDelay() so that the action can occur in the next application cycle or later.

Complete removal of object(s) via display.remove() or object:removeSelf() can be executed during the same collision event time step, but the following APIs and methods can not be called during a collision event:

I will explain what I meant when said buggy

 Collision between player and wall[1]

-If collision angle is 90, player will enter the wall for 1/5 of size

-If collision angle is less than 90, and more than 45, collision will be made 50px in front of wall

-If collision angle is less than 45, collision will go smooth

Thanks for helping :slight_smile:

  1. You may have missed my post-script:

Please give me at least two game examples that have the same or similar player movement. I need the names of the games and/or youtube links of them in action.

  1. Sounds like you have a rectangular body and not a formfitting shape or a circle.

  2. Turn on hybrid draw mode to see the shape of your body and how it interacts with other bodies:

https://docs.coronalabs.com/daily/api/library/physics/setDrawMode.html

  1. Yes, I understand all that about not changing the physics state during a collision, but there is no reason to do so.  You can handle any updates you need one frame later via a timer with a short period (1 ms will do)
  1. This is the nearest i find

https://www.youtube.com/watch?v=3DDWXCc21y0

i have a similar joystick and i get his angle, then:

player:setLinearVelocity( math.sin(math.rad(moves:getAngle())) \* 400, - math.cos(math.rad(moves:getAngle())) \* 400 )
  1. Player is ciricle, it’s reason why i think it will work

  2. hybrid show that player is rect?

    local player = display.newCircle(objects, display.contentWidth/2 + 200, display.contentHeight/2 + 200, 50)

  3. Already check that, no effect

Thanks for fast reply!

That is a 3D game… so super helpful in this discussion.

However, I get the thrust of it. You want to use a joystick to move a player.  

I think you can solve most of your issues by simply  using a circular body.

https://docs.coronalabs.com/daily/api/library/physics/addBody.html

https://docs.coronalabs.com/daily/api/library/physics/addBody.html#circular-body

I don’t know what this meant:

  1. Already check that, no effect

Is this the basic movement you’re talking about?

https://www.youtube.com/watch?v=ShyC11K2te8&feature=youtu.be

If so, SSK2 (lite and PRO)has all the features you need to:

  • handle input
  • set up collisions
  • etc.

It also comes with dozens of samples to help you get rolling.

Hi, thanks a lot, circular body solve a problem with collision when they dont even touching, but player still sometimes go in the wall

For now, i will disable rotating of player.

I’m not sure how much I’m understanding the problem but here are a few suggestions:

  1. Make sure you are rotating the physics objects using physics.  If not, you might be rotating the display object and not the physics object, thus decoupling the display and physics worlds.  This is a common error.  The display object will look fine but the physics will be strange.  Instead of using object.rotation to rotate the physics object, use object.applyAngularImpulse or object.angularVelocity.

  2. Try making the object a bullet.  This forces object to be tracked every frame and is processor intensive but might help if the problem is that your object is moving slightly faster than the calculations.

[lua]

object.isBullet = true

[/lua]