How can I move along an angled collision at a constant speed?

Posted by Raven Dreamer on Game Development See other posts from Game Development or by Raven Dreamer
Published on 2012-07-08T21:07:33Z Indexed on 2012/07/08 21:23 UTC
Read the original article Hit count: 396

I have, for all intents and purposes, a Triangle class that objects in my scene can collide with (In actuality, the right side of a parallelogram).

My collision detection and resolution code works fine for the purposes of preventing a gameobject from entering into the space of the Triangle, instead directing the movement along the edge.

enter image description here

The trouble is, the maximum speed along the x and y axis is not equivalent in my game, and moving along the Y axis (up or down) should take twice as long as an equivalent distance along the X axis (left or right).

Unfortunately, these speeds apply to the collision resolution too, and movement along the blue path above progresses twice as fast. What can I do in my collision resolution to make sure that the speedlimit for Y axis movement is obeyed in the latter case?

Collision Resolution for this case below (vecInput and velocity are the position and velocity vectors of the game object):

// y = mx+c
lowY =  2*vecInput.x + parag.rightYIntercept ;

...

else
{
    // y = mx+c
    // vecInput.y = 2(x) + RightYIntercept
    // (vecInput.y - RightYIntercept) / 2 = x;

    //if velocity.Y (positive) greater than velocity.X (negative)
    //pushing from bottom, so push right.
    if(velocity.y > -1*velocity.x)
    {
        vecInput = new Vector2((vecInput.y - parag.rightYIntercept)/2, vecInput.y);
        Debug.Log("adjusted rightwards");
    }
    else
    {
        vecInput = new Vector2( vecInput.x, lowY);
            Debug.Log("adjusted downwards");
    }
}

© Game Development or respective owner

Related posts about XNA

Related posts about c#