Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
gdevelop5:all-features:collisions [2018/10/14 23:38]
valiant_curiosity [Detect collisions with the Physics behavior]
gdevelop5:all-features:collisions [2019/06/13 21:41]
piyushpalawat99
Line 3: Line 3:
 Most games need to detect and handle collisions between objects. Detecting and handling collisions can be done to make objects stick on platforms, as well as to detect collisions between bullets and players or bullets and other objects. Most games need to detect and handle collisions between objects. Detecting and handling collisions can be done to make objects stick on platforms, as well as to detect collisions between bullets and players or bullets and other objects.
  
-GDevelop provides several different ways to handle collisions. You can detect collisions using  Event Editor conditions and actions or you can use Object behaviors.+GDevelop provides several different ways to handle collisions. You can detect collisions using Event Editor conditions and actions or you can use Object behaviors.
  
-## Make objects solids: use the "​Separate objects"​ action (good for top down games, RPG...)+## Make objects solids: use the "​Separate objects"​ action (good for top-down games, RPG...)
  
 You can use the "​**Separate objects**"​ action to move objects manually. The "​Separate objects action can also move objects with "​forces"​ or by setting the object position. You can use the "​**Separate objects**"​ action to move objects manually. The "​Separate objects action can also move objects with "​forces"​ or by setting the object position.
Line 13: Line 13:
   * The second object name is an //object (or a group of objects) that are solid//. For example, these objects can be the walls.   * The second object name is an //object (or a group of objects) that are solid//. For example, these objects can be the walls.
  
-The action will then iterate over all of the objects given. It will ensure that if any object of the first kind is colliding with the object of the second kind, the object will be moved away. This is done using an algorithm called the _SAT algorithm_.+The action will then iterate over all of the objects given. It will ensure that if an object of the first kind is colliding with an object of the second kind, the object will be moved away. This is done using an algorithm called the _SAT algorithm_.
  
 {{ :​gdevelop5:​all-features:​separate-objects-action.png?​nolink |}} {{ :​gdevelop5:​all-features:​separate-objects-action.png?​nolink |}}
  
-This action will be launched ​at every frame. In an event without conditions, the action ​ is already doing the collisions checks. Avoid launching this action multiple times. Doing so could reduce game performance.+This action will be launched ​in every frame. In an event without conditions, the action is already doing the collisions checks. Avoid launching this action multiple times. Doing so could reduce game performance.
  
 ### Detect collisions ### Detect collisions
  
-Using the "​Separate objects"​ is a good way to ensure that your objects can't move into other solid objects. This action ​ checks collisions between objects. For example, if the game object "​player"​ is touching a wall this action, when used with the condition called "​**Collision**",​ will trigger damages to the player. ​+Using the "​Separate objects"​ is a good way to ensure that your objects can't move into other solid objects. This action checks collisions between objects. For example, if the game object "​player"​ is touching a wall this action, when used with the condition called "​**Collision**",​ will trigger damages to the player. ​
  
 **The sequence is important.** ​ **The sequence is important.** ​
Line 35: Line 35:
 Open this example online: https://​editor.gdevelop-app.com?​project=example://​bomb-the-crate</​note>​ Open this example online: https://​editor.gdevelop-app.com?​project=example://​bomb-the-crate</​note>​
  
-[[https://​editor.gdevelop-app.com?​project=example://​bomb-the-crate|{{ :undefined:checkccollisionbetweenobjects.png?200 |}}]]+[[https://​editor.gdevelop-app.com?​project=example://​bomb-the-crate|{{ :gdevelop5:all-features:​checkccollisionbetweenobjectsnew.png? |}}]]
  
  
 ## Platformer games: use the Platformer character and Platform behaviors ## Platformer games: use the Platformer character and Platform behaviors
  
-If you're making a platformer game, it's a good idea to use the [[gdevelop5:​behaviors:​platformer|"​Platformer character"​ behavior]]. It's a ready-made platform game engine that is highly customizable. The "​Platformer character"​ behavior handles collisions with the platforms ​an the gravity ​for you.+If you're making a platformer game, it's a good idea to use the [[gdevelop5:​behaviors:​platformer|"​Platformer character"​ behavior]]. It's a ready-made platform game engine that is highly customizable. The "​Platformer character"​ behavior handles ​the gravity and the collisions with the platforms for you.
  
 ### Detect collisions in a platformer game? ### Detect collisions in a platformer game?
  
-In a platformer game with the "​Platformer character"​ behavior, collisions are handled for you with platforms.+In a platformer game with the "​Platformer character"​ behavior, collisions ​with platforms ​are handled for you.
  
 * You can still use the **Collision condition** to check for collisions between an object and other objects (for example, between the player and enemies) and react accordingly. * You can still use the **Collision condition** to check for collisions between an object and other objects (for example, between the player and enemies) and react accordingly.
Line 56: Line 56:
 ## Game with physics? Use the Physics behavior ## Game with physics? Use the Physics behavior
  
-Use [[gdevelop5:​behaviors:​physics|Physics behavior]] in order to achieve realistic physical behavior in your game. Attach "​Physics"​ behavior to your objects. The objects will then behave as though they are based alive in the game world. Some examples of real world behavior are bouncing balls, falling, jumping, etc. +Use [[gdevelop5:​behaviors:​physics|Physics behavior]] in order to achieve realistic physical behavior in your game. Attach "​Physics"​ behavior to your objects. The objects will then behave as though they are based alive in the game world. Some examples of real-world behavior are bouncing balls, falling, jumping, etc. 
  
 Configure game walls or solid objects that should not move with "​static"​ behavior. Configure game walls or solid objects that should not move with "​static"​ behavior.
Line 64: Line 64:
 When you're using the "​Physics"​ behavior, **do not use** the "​Collision"​ condition that is in the **Features for all objects** category. //The physics engine will manage all collisions by itself.// ​ The Collision condition won't properly detect when objects are touching. When you're using the "​Physics"​ behavior, **do not use** the "​Collision"​ condition that is in the **Features for all objects** category. //The physics engine will manage all collisions by itself.// ​ The Collision condition won't properly detect when objects are touching.
  
-Instead, use the Collision condition **inside the Physics behavior category**, which properly uses the physics engine to listen to collisions. ​+Instead, use the Collision condition **inside the Physics behavior category**, which properly uses the physics engine to simulate the collisions. ​
  
-{{ :​gdevelop5:​all-features:​usephysicsbehaviornotcollisioncondition.png?400 |}}+{{ :​gdevelop5:​all-features:​usephysicsbehaviornotcollisionconditionnew.png? |}}