Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 26 Jul 2012
Offline Last Active Oct 20 2014 02:19 PM

Posts I've Made

In Topic: Getting a rectangle to land on top of a rectangle

01 June 2014 - 07:30 AM

When I want the camera to follow an object I multiply the camera matrix with the object matrix. So it follows/rotates/scales with the object (I usually disable scaleWithParent).

I recommend to read this article: http://www.gamedev.net/page/resources/_/technical/math-and-physics/making-a-game-engine-transformations-r3566

In Topic: 2D chase steering algorithm

31 May 2014 - 03:31 AM

It sounds like you can get your objects to reach a point, can you get the objects to reach where they think the player will be?  Take a look at the player's velocity, and figure out where it will be in x milliseconds from now, and have the object steer to that point?

I already do, this is what the method GetIntersectionOffset() does (The shots need to have the same tangential velocity as the player relative to the enemy to hit the player). But I can't find the acceleration the enemy needs to keep up with the player :(

In Topic: Democratic Chess

30 May 2014 - 05:25 PM

How many Facebook friends do you have? Pretty easy test bed. Build a chess board with free move pieces and send it to all your friends. Send out a notice for a white move. Collect white moves. Post the updated board with the voted on move(maybe some of the the popular votes) and the notice for a black move. Take a re-vote on ties. You might have to do a lot of the initial work by msging or posting unless you know how to dig into facebook. But either way you'll get some feedback. The unique idea behind this experiment is allowing everyone to vote black and white. Letting the socialization between moves dictate the "side" the players end up favoring. By making it a free move chess board players can show off their knowledge of the game and their willingness to "play along". It would be interesting if you made it through a game. 


Sounds exciting, but I would need to learn from the beginning, I have no clue how multiplayer and databases work. It stays a cool idea, I maybe realize in the future ;-)

In Topic: Getting a rectangle to land on top of a rectangle

30 May 2014 - 05:15 PM

I don't know whether I understood you right, but I think you need to do is intersection resolving. When your moving rectangle collides with the static (and it is not important from which side) you need to find out how deep and from what direction they overlap to push it out so that they are next to each other perfectly aligned but not penetrating.

The code for is tricky. I took it from the XNA's platformer example and modified it a bit. I have not tested the normal it outputs but the rest should work perfectly:

/// <returns>Depth of intersection relative to rectA</returns>
        public static Vector2 GetIntersectionDepth(Rectangle rectA, Rectangle rectB)
            float halfWidthA = rectA.Width / 2f;
            float halfHeightA = rectA.Height / 2f;
            float halfWidthB = rectB.Width / 2f;
            float halfHeightB = rectB.Height / 2f;

            Vector2 centerA = new Vector2(rectA.Left + halfWidthA, rectA.Top + halfHeightA);
            Vector2 centerB = new Vector2(rectB.Left + halfWidthB, rectB.Top + halfHeightB);

            float distanceX = centerB.X - centerA.X;
            float distanceY = centerB.Y - centerA.Y;
            float minDistanceX = halfWidthA + halfWidthB;
            float minDistanceY = halfHeightA + halfHeightB;

            if (Math.Abs(distanceX) >= minDistanceX || Math.Abs(distanceY) >= minDistanceY)
                return Vector2.Zero;

            float depthX = distanceX > 0 ? minDistanceX - distanceX : -minDistanceX - distanceX;
            float depthY = distanceY > 0 ? minDistanceY - distanceY : -minDistanceY - distanceY;
            return new Vector2(depthX, depthY);

        /// <returns>[0] position to add to B [1] normal</returns>
        public static Vector2[] ResolveIntersection(Rectangle rectA, Rectangle rectB)
            Vector2 depth = GetIntersectionDepth(rectA, rectB);
            Vector2 normal;

            if (Math.Abs(depth.X) > Math.Abs(depth.Y))
                if (depth.Y > 0) normal = Vector2.UnitY; else normal = -Vector2.UnitY;
                if (depth.X > 0) normal = Vector2.UnitX; else normal = -Vector2.UnitX;

            if (Math.Abs(depth.X) > Math.Abs(depth.Y))
                return new Vector2[2] { new Vector2(0, depth.Y), normal };
                return new Vector2[2] { new Vector2(depth.X, 0), normal };

Hope I could help, Phil

In Topic: Democratic Chess

29 March 2014 - 08:56 AM

Thanks for your feedback! Unfortunately, I know too little about networking and browser-programming to do this (and I have no large group I could test the idea with), so it will remain a thought experiment.