Hello Guest

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - JonDavis23

Pages: [1]
1
Support / Re: Collisions with small box colliders
« on: June 10, 2012, 08:18:12 pm »
I was able to work out my gravity issues and it runs well on the iPhone.  If anyone is interested here are the changes I've made.
At first I was lerping to the final position but it was giving me an undesired slowing down effect, so I switched to Sinerp.

Code: [Select]
void FixedUpdate()
    {
        if (Physics.Raycast(myTransform.position, Vector3.down, out hit, 1))
        {
if (coinComponent.IsFalling)
{
tempLayer = hit.transform.gameObject.layer;
// 9 = Coin
// 8 = Lift
            if (tempLayer == 8 || tempLayer == 9)
            {
                    // It's stoping here.
                    // Determine if this is the right row, if so. sinerp the y pos if necessary
                    SetPrecisePosition(coinComponent.Row);

                    if (myTransform.position.y != preciseYPos)
{
// Lerp eases to the end. Lerp appears to add jerkiness near the end of its run.
// Switched to Sinerp
yPos2 = Mathfx.Sinerp(myTransform.position.y, preciseYPos, (FallSpeed * 3.5f) * Time.deltaTime);

tempVector.x = myTransform.position.x;
tempVector.y = yPos2;

myTransform.position = tempVector;
}
                    else
                        coinComponent.IsFalling = false;
                }
            }
        }
        else
        {
            // Hit nothing, falling
            coinComponent.IsFalling = true;
            coinComponent.Triggered = false;

            myTransform.Translate(Vector3.down * FallSpeed * Time.deltaTime);
        }
    }

public static float Sinerp(float start, float end, float value)
{
        return Mathf.Lerp(start, end, Mathf.Sin(value * Mathf.PI * 0.5f));
}


2
Support / Re: Collisions with small box colliders
« on: June 07, 2012, 06:51:04 pm »
I changed the scale from .25 to (1.075, 1.075, 1.2). I was afraid the sprites would be too large, but then I remembered I could change the Size property on the camera.
I'm trying to get a consistent distance between letters once the gravity stops.  I'm guessing its the Raycast that isn't in sync?

FallSpeed is set to 5

Code: [Select]
    void FixedUpdate()
    {
        var moved = FallSpeed * Time.deltaTime;
        var offsetVector = new Vector3(0, myTransform.collider.bounds.size.y / 2, 0);
        var offsetPosition = myTransform.position - offsetVector;

        if (Physics.Raycast(offsetPosition, Vector3.down, out hit, moved))
        {
            if (hit.transform.tag == "Coin" || hit.transform.tag == "Lift")
            {
                if (coinComponent.IsFalling)
                    coinComponent.IsFalling = false;
            }
        }
        else
        {
            // Hit nothing, falling
            coinComponent.IsFalling = true;
            coinComponent.Triggered = false;

            myTransform.Translate(Vector3.down * FallSpeed * Time.deltaTime);
        }
    }

3
Support / Collisions with small box colliders
« on: June 01, 2012, 06:48:09 pm »
I'm having issues with my rigidbodies falling through each other slightly.

Im creating a boggle clone, with a 5x6 grid of letters. Each letter has a rigid body that is non kinematic, interpolation is Interpolate, and Collision Detection is Continuous Dynmaic. When the user forms a word, the letters are deleted and new ones fall from above. I'm using triggers to determine the row / col position of the letters, this is why I'd like to use rigidbodies.

I'm using rigidbody.MovePosition() to handle movement. Everything worked fine until I tried moving this to the iPhone. On the computer, a Fixed Timestamp of 0.001 works fine, but it crawls on the phone. Updating the Fixed Timestamp between 0.04 - 0.067 greatly increases the speed, but the collisions are no longer accurate.

The box collider size on my tk2dsprite is (.25f, .25f, .25f).  I know this is really small and most likely the cause of my issue, but that size encompasses my letters and anything larger would have too much space between my letters.

Is there a method to check for overlapping sprites in 2D Toolkit?

Any advice on increasing collision accuracy and mainting a good fps would be greatly appreciated.

Thanks

Pages: [1]