Announcement

Collapse
No announcement yet.

Need some instructions

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • panky
    started a topic Need some instructions

    Need some instructions

    Hi guys!

    I would like to create a similar game: http://www.maxgames.com/play/age-of-war-2.html

    Units that are going against each other, they can't be in the same place, except at the beginning (near the two towers).

    How can I control this behavior of the units? With colliders? If you have some tips or sample, it's would be great.

  • panky
    replied
    Solved. Here is my solution, maybe this will help someone.

    Rectangle extensions: http://gamedev.stackexchange.com/que...gle-intersects

    RectangleCollider extension:
    public static class RectangleColliderEx
    {
    public static RectangleF CollisionBox(this RectangleCollider collider)
    {
    return new RectangleF { X = collider.Transform2D.X, Y = collider.Transform2D.Y, Width = collider.Transform2D.Rectangle.Width, Height = collider.Transform2D.Rectangle.Height };
    }
    }
    sample:

    var cb1 = collider1.CollisionBox();
    var cb2 = collider2.CollisionBox();
    var depth = cb1.GetIntersectionDepth(cb2);

    // depth.X < 0 => Right
    // depth.X > 0 => Left
    // depth.Y < 0 => Bottom
    // depth.Y > 0 => Top

    Leave a comment:


  • panky
    replied
    Thanks for the answer, I checked the samples. My problem is that, I can't verify that on which side occured the collision. I tried with perpixelcollider and rigidbody2d, it's working but I don't want to use physics (unnecessary for this).

    Leave a comment:


  • juanlao
    replied
    Thanks for the post panky!

    Colliders is the typical way to achive the behavior you want.
    Please take a look at the Browser Sample in the download section. It contains tons of mini samples.

    Hope this helps

    Leave a comment:

Working...
X