Jump to content

Detect which side of the sprite is colliding


Recommended Posts

I have a sprite using Arcade Physics, and a tile-map layer that ive set every tile index in it to collide with the sprite. Because its sprite vs tilemap layer instead of sprite vs sprite the engine sets sprite.body.blocked, not sprite.body.touching.


This is all grand and every where ive searched on the forums this information was enough for the person asking. However up, down, left and right is not in relation to the sprites rotation, but seems to be in relation to the map. 


I have a topdown car that drive around a track (Micro Machines style). What i want is to be able to say which side of the car is colliding taking into account it's rotation.


The reason being if you collide on the front and turn slightly it will slide along the collided object. I don't want that, i want to stop the user being able to go forward if they collide on the font of the sprite, or at least change its maximum speed it can move when the front is touching something. 


Hope all that makes sense. Thanks everybody.

Link to comment
Share on other sites

Wouldn't it be simple to the point of triviality to calculate a direction value (up, down, left, right) from your sprite's rotation (degrees)?


Don't think i follow, how would that help me work out which side of the sprite is colliding? Its not just driving forwards into things, you could slide into them (When on ice, drifting, handbrake turns), you can reverse into them etc. Does the sprite contain a point object as to the location of the collision which could be used with your idea?



Link to comment
Share on other sites

When you collide, you know where in relation to the car the object you collided with is. So you check how that matches up with where your car is pointing at the moment, wich you also know. When your car is rotated so that the front points left, and you collide with touching.left = true, then you know it's a head-on collision.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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