Jump to content

Check collision by position with Arcade Physics?


BlueLemming
 Share

Recommended Posts

Is there a way to check if a physics sprite would collide with another object at a given position? I have tried something like this:

 


  // desired position to check player collision at
  const checkPosition = { x: 100, y: 100 }

  // temporarily change player position
  const pos = { x: player.x, y: player.y }
  player.setPosition(checkPosition.x, checkPosition.y)
  
  // test collision
  const collision = this.scene.physics.collide(player, otherObj)

  // set back to original position
  player.setPosition(pos.x, pos.y)

 

however, I can't get the collision to return true. I suspect there needs to be an update cycle between updating the position and testing for collisions, but I can't find any documentation to suggest that is the case.

Is there a good way to go about this?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...