Update the Quick Start Project (Collider Component)

Hi,

I was looking at: https://github.com/cocos-creator/creator-docs/blob/master/source/en/getting-started/quick-start.md

And it is a great, amazing example for a first game but it uses the logic of calculating the distance between the player and the stars to determine if the player collected a star. Are there any plans to update this tutorial to incorporate how to use Collider Component to complete this action?

Any documentation on the Collider Component would be greatly appreciated. Thank you.

1 Like

Hi @efares,

Are you looking for how to collide 2 objects with code? God Bless…

Sincerely,

Sunday

Hi @luke2125,

I’m looking to see how to implement collision detection between 2 nodes/objects using Cocos Creator (component + code).

Thanks.

Download the example project and you can find the usages there. Good luck!

1 Like

Hi @efares,

This is how I set it up in my game:
player.node
onLoad: function () {
var collidemanager = cc.director.getCollisionManager();
** collidemanager.enabled = true;**
//collidemanager.enabledDebugDraw = true;
// collidemanager.enabledDrawBoundingBox = true;

onCollisionEnter: function (other,self) {
//this.node.color = cc.Color.RED;
this.touchingNumber ++;

   //Collides with Food Objects Increase Health +5  -- Function// 
   if(other.node.name=="food1prefab") {this.PlayerHealthIncrease()} 
  if(other.node.name=="food2prefab") {this.PlayerHealthIncrease()} 
  if(other.node.name=="food3prefab"){this.PlayerHealthIncrease()} 
  if(other.node.name=="food4prefab"){this.PlayerHealthIncrease()} 
  if(other.node.name=="food5prefab"){this.PlayerHealthIncrease()} 
  if(other.node.name=="food6prefab"){this.PlayerHealthIncrease()}             
         },

onCollisionStay: function (other,self) {
    // console.log('on collision stay');
          },

onCollisionExit: function (other,self) {
    this.touchingNumber --;
    if (this.touchingNumber === 0) {
        this.node.color = cc.Color.WHITE;
      
}},

Also, make sure you add the collider component to the particular node, and then from such node, in drop-down menu, choose group -> player (example). Then make sure, you add such to group through Project Settings -> Group Manager, and place colliding check-mark accordingly… I don’t know now, with the upcoming implementation of the physics engine, if the workflow would change though? Hope this helps…God Bless…

Sincerely,

Sunday

1 Like