Can I move dynamic physics bodies using SKAction when only contact detection is needed?

蓝咒 提交于 2020-01-13 06:28:06

问题


I am looking at tutorial where things are defined like this:

  • planes are sprites with dynamic physics bodies
  • plane moving is done with actions by following the path
  • there is contact detection between bullet and plane
  • bullet is sprite and it has physics body set to be static (which is little unusual in my opinion)

Here is the link to tutorial for more information.

Questions:

  1. When we use actions to move physicsBodies is there a difference how we set body's dynamic property? Because bullet is static but still there is no problem for movement.

  2. When we have situation like this, where we don't need collision detection, but just contact detection, and we can't move sprites (enemies) by applying forces or impulses, what is a good approach? Is this approach correct?

I think this is nice way, but I would like to be fully aware what is really happening when we use this method and are there any drawbacks or possible problems.

There are posts on SO that suggest we shouldn't use actions for moving dynamic physics bodies. I am aware that we can't use this approach in every case. For example this would not work for moving platform with other object on it, because there would be no correct physics simulation between body on the platform and platform moved by action. But in cases like from this tutorial, where we only need contact detection for object that can be moved only by actions (moved along path) I suppose it's not a problem ?


回答1:


  1. static means that the body isnt affected by physics. That doesnt mean it cant be manually repositioned or moved. So if something is set to static, it participates in the physics simulation, but it isnt affected by it. Think of a plane hitting a mountain. The plane is dynamic, the mountain is just going to sit there even though its participating in the physics. But you could still move that mountain around manually using a position or an action.

  2. Not totally understanding your question, but I'll give it a shot.

You can move physicsBody's manually (using position property or actions), but you need to ask yourself why you're doing that. You typically don't want to do it because they're bypassing the physics simulation. If you're forcing it to move around, what's the point of using a physics body in the first place.. right?

But if your physicsbody is something like a powerup that is totally static, and you just want it to move around in a circle using an action then thats fine. You probably just want to use contact detection for the bullet, powerup, etc without actually moving it around using physics. Nothing wrong with that.



来源:https://stackoverflow.com/questions/28356713/can-i-move-dynamic-physics-bodies-using-skaction-when-only-contact-detection-is

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!