Ask coding questions

← Back to all posts
Kaboom.js How can I change the direction of a sprite when he hits a wall?
Guelprix (0)

As I was coding along with Ania Kubow´s Mario Tutorial, I noticed that the goomba will get stuck, if he walks into a wall. I wanted him to change his walking direction, if he hits a wall or a pipe. Tried it out my own first, but doesn´t seem to work that way :/(commented out line 207-213).
Thanks for your help

Comments
hotnewtop
Coder100 (18928)

Did you miss some parts of the tutorial?
There should be code like this:

collides("dangerous", "wall", (d, w) => {
  d.dir *= -1;
});
Guelprix (0)

@Coder100 i already tried that one but the goomba does not move at all

Guelprix (0)

no everything else is working well @Coder100

Guelprix (0)

but is there a possibility that d.dir is not defined and
doesnt work for this reason? @Coder100

Coder100 (18928)

@Guelprix yeah, you didn't define it

Coder100 (18928)

maybe you can invite me and I will fix it for you @Guelprix

Guelprix (0)

i dont know how to I´m new to coding could you explain me how to do it? @Coder100

Coder100 (18928)

click the invite button @Guelprix

Guelprix (0)

invited you if you are making any changes could you add a comment on what you did that would be very helpful @Coder100