Skip to content
Sign upLog in
← Back to Community

Kaboom.js How can I change the direction of a sprite when he hits a wall?

Profile icon
Guelprix

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

Voters
Profile icon
Guelprix
Comments
hotnewtop
Profile icon
Coder100

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

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

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

Profile icon
Coder100

is there an error?


@Guelprix

Profile icon
Guelprix

no everything else is working well

@Coder100

Profile icon
Guelprix

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

@Coder100

Profile icon
Coder100

@Guelprix
yeah, you didn't define it

Profile icon
Coder100

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

@Guelprix

Profile icon
Guelprix

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

@Coder100

Profile icon
Coder100

click the invite button

@Guelprix

Profile icon
Guelprix

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

@Coder100

Profile icon
JudithNelson

@Guelprix
did you ever get this sorted? I am new to kaboom and having the same problem, collision event plays for ever