find parent object's collision

hi!
I’m trying to do something like the pitcture displays and for many reasons I’m avoiding to use rigidbodys and physics. There are also no character controllers attached to the player, just a sphere collider.

Assuming I control the hammer rotation with a simple input lef-right, I’m trying to stop the rotation of the hammer when it reach the pawn.

I had no trouble with planar moving and colliding (and whatever that matters with the plane), but with rotation and particularly with eccentric rotation I find some problems to get a collision.

I tried a controller based on triggers, but it does’t work well…

Every suggestion is well accepted!

tx

Hello there!

Okay, if you want to do this without rigidbodies and physics then using triggers sounds like a reasonable idea.
I presume you do your rotations in the update function, so adjust your rotation script to include this functionality:

private int mLastRotationDirection;
private int mLockedRotationDirection = 0;

void Lock(bool lock)
{
    if(lock)
        mLockedRotationDirection = mLastRotationDirection;
    else
        mLockedRotationDirection = 0;
}

void Update()
{
    if(Input.GetKey(KeyCode.LeftArrow)  mLockedRotationDirection != -1)
    {
        mLastRotationDirection = -1;
        // Your rotation code
    }
    else if(Input.GetKey(KeyCode.RightArrow)  mLockedRotationDirection != 1)
    {
        mLastRotationDirection = 1;
        // Your rotation code
    } 
}

void OnTriggerEnter(Collider collision)
{
    if(collision.tag == "StopHammer")
        Lock(true);
}

void OnTriggerExit(Collider collision)
{
    if(collision.tag == "StopHammer")
        Lock(false);
}

However you might encounter a problem: without a rigidbody attatched to the hammer collision events probably will not fire. You can solve this by adding a rigidbody to your hammer, disabling gravity and set it to IsKinematic.

Oh, and don’t forget to add a “StopHammer” tag to your unfortunate guy who will endure the wrath of the hammer!

P.S: I seem to recognize this art style, are you by any chance working with MrSpeedWagon?

Thanks a lot! script works well and now we can proceed with our game (yes, I’m with mr-speedwagon)

since the collision doesn’t work with object rotating instead of translating, you think is possible to use a system based on triggers for achieve a physic-like collision system? (sorry for the dumbness)

tx!