Hello Guest

Author Topic: Advanced Collision with angle  (Read 4062 times)

mukarillo

  • Newbie
  • *
  • Posts: 16
    • View Profile
Advanced Collision with angle
« on: September 27, 2015, 07:03:13 pm »
Hi there,

I'm using Advanced Collision to make a fighting game. I've managed to compare two rects to check for collision using this code:

Code: [Select]
float originX = (currentSprite.FlipX) ? -currentSprite.CurrentSprite.customColliders[i].origin.x : currentSprite.CurrentSprite.customColliders[i].origin.x;
Rect collisionRect = new Rect(
(gameObject.transform.localPosition.x+originX)-currentSprite.CurrentSprite.customColliders[i].Size.x/2,
(gameObject.transform.localPosition.y+currentSprite.CurrentSprite.customColliders[i].origin.y)-currentSprite.CurrentSprite.customColliders[i].Size.y/2,
currentSprite.CurrentSprite.customColliders[i].Size.x,
currentSprite.CurrentSprite.customColliders[i].Size.y);

But now i'm facing another problem, i got a sprite with a 45 degree angle, like this:

But when I run that code into this kind of image, this happen:


I coudn't find a way to rotate a Rect, how can i do that?

Thanks! :D
« Last Edit: September 28, 2015, 03:11:26 pm by mukarillo »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Advanced Collision with angle
« Reply #1 on: October 04, 2015, 12:47:27 pm »
Hi,

You can't rotate a unity Rect class, it doesn't carry any rotation information. I don't think Unity has any built in box-box collision without using physics which will be overkill. You could write your own overlap test class (http://www.gamedev.net/page/resources/_/technical/game-programming/2d-rotated-rectangle-collision-r2604) somethign like that will do the job.