Skip to content
← Back to Community
Create a solid wall if you know when the character is intersecting with the wall in p5.js
Profile icon
CrazyVideoGamer

Hello, I'm working on a kinda crappy platformer, and I need to create a wall. I have a function that tells you if the character (cat) is intersecting with the wall. I want to find a way to stop the character from going into the wall. I want the character to be able to stand on top of a wall and also be stopped when walking into a wall.

Voters
Profile icon
JaydenSeah
Profile icon
CrazyVideoGamer
Comments
hotnewtop
Profile icon
neethumadster

Virtual dressing room by VueModel allows shoppers to visualize and style products on relatable models of various shapes, sizes, ethnicities in real time.Make your eCommerce site come alive with a Virtual dressing room.Dressing Room by VueModel helps retailers deliver personalized, inclusive virtual dressing room experiences in their eCommerce stores. Shoppers can mix & match looks, and visualize how they fit on models that most resemble them.

Profile icon
TannerTommy

This is a great way to create a solid wall, and I want to thank the writer here for sharing this valuable information here. I will keep the drywall contractor updated about this. He was quite interested in this, as well.

Profile icon
19wintersp

Wherever you're updating the sprite's position, change the position virtually without updating the actual position, and check if that new position intersects with the wall. If it does, don't actually change the position?

Profile icon
CrazyVideoGamer

@19wintersp hmm, I'll try that

Profile icon
CrazyVideoGamer

@19wintersp I tried adding it to the Player.js file (using checkWallIntersectionBeforePosChange), but it's not really working, now the Player is bugged. Can you please tell me why? thx

Profile icon
19wintersp

@CrazyVideoGamez I think it's because you're checking the collision between the current position and the wall (Player.js:156), rather than the x and y arguments.

Profile icon
CrazyVideoGamer

@19wintersp Ok, I am now using an updated bounding box. But it still isn't working 🤔.

Profile icon
ABadGamer73

@CrazyVideoGamez so maybe you have to triple check your code or something

Profile icon
19wintersp

@CrazyVideoGamez You're not though:

let newBoundingBox = { tL: createVector(this.pos.x, this.pos.y), // tR: [this.pos.x + 25 + 126, this.pos.y + 6], // bL: [this.pos.x + 25, this.pos.y + 6 + 94], bR: createVector(this.pos.x + this.catWidth, this.pos.y + this.catHeight) }

just creates a bounding box from the existing position (this.pos). You need to use x and y:

let newBoundingBox = { tL: createVector(x, y), bR: createVector(x + this.catWidth, y + this.catHeight) }
Profile icon
CrazyVideoGamer

@19wintersp Ok, I put in the new position instead of the old position, but it is now REALLY glitchy.

Profile icon
CrazyVideoGamer

@19wintersp btw variables x, y don't exist so ya

Profile icon
19wintersp

@CrazyVideoGamez They're passed to the function as parameters.

Profile icon
CrazyVideoGamer

@19wintersp I updated the function to take in a bounding box

Profile icon
19wintersp

@CrazyVideoGamez Where are you calling it from?

Profile icon
CrazyVideoGamer

@19wintersp mb, I'm still trying to fix the bugs. Go to player_old.js, it will be in there, called inside of the function display

Profile icon
19wintersp

@CrazyVideoGamez You're still changing the bounding box even when it would collide.

Profile icon
CrazyVideoGamer

@19wintersp ok, I fixed that, but now the cat is going crazy

Profile icon
CrazyVideoGamer

@19wintersp Oh and also, checkWallIntersectionBeforePosChange is broken, because it only returns false when the cat reaches the end, and I don't god f'ing know why
it's so painful