Invisible Sprite

How do I create a invisible sprite that the player can pass through, but the enemy can not?

I tried this, but the player cannot pass through the invisible sprite “space.”

  player.collides("space", (space) => {
    solid(false);
  });
   onCollide("enemy","space", (space) => {
    solid(true);
  });

Is there something I’m missing? Or am I doing this completely wrong?

Hey @EllaBerrett! Welcome to the community!

Could you send the cover page link to your Repl? This will help us pinpoint where the issue is located in your Repl.

1 Like

https://replit.com/@EllaBerrett/Dragon-Hunt
(Line 375)

Let me know if the link doesn’t work…

Hmm… I have never tried Kaboomjs before… I will try to give my best shot at helping you though:

You can set the sprite’s transparency to zero by adding a color() like this:

// …
add([
    sprite("space"),
    color(0, 0, 0, 0)
])
// …

Then add a isColliding() to the enemy sprite:

// …
// move enemy
if (enemy.isColliding("space")) {
    // move enemy back
}

If there is someone who is more experienced with Kaboomjs comes by and is able to give you a better answer, mark their post as solution. I am just reading from the docs.

1 Like

I believe this is deprecated?

collisionIgnore: Tag[]
If this object should ignore collisions against certain other objects.

This is from the Kaboom 3000 site, would probably be used like this:

add([
  ...
  area({ collisionIgnore: ... }),
]);
2 Likes

Thank you all, I’ll let you know if any of this works!

We found a different solution, but thanks anyway!

Please tell us the solution so that way other people with the same issue can find the solution too!

2 Likes

We destroyed the invisible sprite instead:

  player.collides("space", (space) => {
    destroy(space); 
  });
2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.