No announcement yet.

Need some instructions

  • Filter
  • Time
  • Show
Clear All
new posts

  • Need some instructions

    Hi guys!

    I would like to create a similar game:

    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.

  • #2
    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


    • #3
      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).


      • #4
        Solved. Here is my solution, maybe this will help someone.

        Rectangle extensions:

        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 };

        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