Create a solid wall if you know when the character is intersecting with the wall in p5.js
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.
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.
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?
@19wintersp hmm, I'll try that
@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
@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.
@19wintersp Ok, I am now using an updated bounding box. But it still isn't working 🤔.
@CrazyVideoGamez so maybe you have to triple check your code or something
@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) }
@19wintersp Ok, I put in the new position instead of the old position, but it is now REALLY glitchy.
@19wintersp btw variables x, y don't exist so ya
@CrazyVideoGamez They're passed to the function as parameters.
@19wintersp I updated the function to take in a bounding box
@CrazyVideoGamez Where are you calling it from?
@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
@CrazyVideoGamez You're still changing the bounding box even when it would collide.
@19wintersp ok, I fixed that, but now the cat is going crazy
@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
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.