RAM Swimming help (dynamic level detection)

nathanj

Active member
Hello,


One thing I am not sure about is Collision detections only work if the rigidbody is set to none Kinematic, meaning that I need to assign an additional rigidbody and collider to the character for the detection. Is there a better way to do this anyone can think of?

Thanks in advance, any help is most appreciated.

Nathan
 
Last edited:
Hi Nathan, what collision detection are you trying to achieve with a rigidbody/what feature are you trying to implement? The character controller is based around using a kinematic rigidbody, so trying to use a non-kinematic one could cause issues.
 
Hi Andrew

Thanks for your help, again.

The thing with RAM water is it allows for uneven water heights, we have many deep creeks that flow dow the terrain so using simple box colliders for setting the water height doesn't work.

I'm trying to use this Water Setup recomendation so I have a box collider trigger around the whole RAM mesh and then using a collision detection between the player and RAM's Mesh Collider to set the Swim abilities SetWaterSurfacePosition value. But on Start UCC overrides all of the children Rigidbodies on the character to isKinematic. I did try adding an additional non kinematic one but this seems to cause weird behaviour, like you suggested would possibly happen.

So I guess my question is, do you have any idea of another way to use the player (or npc) to dynamically detect the height of the Mesh Collider for each RAM water source? I'm thinking possibly a raycast hit? But before I go down that road was just wondering if you had any other suggestion to try?

If you do suggest using a raycast would you mind explaining how you would approach that?

Much appreciated,
Nathan
 
Last edited:
Hm well I'm not familiar with the RAM Water package and how it generates/uses meshes, if you're able to provide a couple of screenshots showing an example of what it would look like in-game with the collider meshes and whatnot that would be useful.

So if I'm understanding correctly, you need to be able to dynamically determine the topmost point of the mesh for the body of water that the player is currently in, for setting the water surface position in the swim ability. If the meshes cover quite large areas and the surface position doesn't vary too much across each one, then you could probably just use a separate trigger box collider for each one and adjust the colliders so that they reach the top of the surface for each area?

If the water surface level varies more often than that and you need something more dynamic, then maybe a raycast is the way to go. E.g. maybe raycast from the player's root position in a straight vertical line upwards, which would stop when it collides with the water surface, which would give you the water surface position's Y value. Or if that's not possible, maybe you'd have to start the raycast from above the water surface pointing down.

Sorry for the vague suggestions, but as I said I'm not familiar with what these mesh colliders look like so I'm not sure on the specifics.
 
Hey,

So i finally got it working using a Raycast that is a child of the player.


Code:
  private void Start()
    {
        StartCoroutine(CheckWaterLevel());
        ucl = gameObject.GetComponentInParent<UltimateCharacterLocomotion>();
       if(ucl) swim = ucl.GetAbility<Swim>();
    }
    IEnumerator CheckWaterLevel()
    {
        while (true)
        {
            yield return new WaitForSeconds(1);
            if (Physics.Raycast(transform.position, Vector3.down, out hitPoint,1f, layerMask, QueryTriggerInteraction.Collide))
            {
                print("Water Height " + hitPoint.point.y);
                if (ucl) swim.SetWaterSurfacePosition(hitPoint.point.y);
            }
        }
    }

I ended up having to assign the box collider that enables the swim ability to another layer (Satellites) and have it encapsulate the whole scene and then use the Water layer for the raycast detection to set the hight value.



RAMSwim.PNG

But, woop! can not tell you how happy I am to finally have this working.

Thanks again for your time and direction.

Nathan
 
Last edited:
Hey,

One more question on this, is there a way to have the water ability automatically start without requiring a Trigger detection?

If I set the detection to "None" (it's set to Trigger by default for the Swim ability) I haven't been able to enable the swim ability to then register the RAM water detected level.

Thank you,
Nathan
 
OK, I'm sure i tried that and for some reason it returned false. I'll try again.

Apologies for the ridiculous question ;)
 
Top