This topic contains 4 replies, has 2 voices, and was last updated by  Cyrawnis 6 months, 4 weeks ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #39837

    Cyrawnis
    Participant

    Hello everyone,

    I’m fairly new to Rain, and I seem to be having trouble returning the velocity of an object’s rigidbody.

    What I am trying to do:
    - Create a cube as the navigator
    - Create Rain Navigation Mesh
    - Attach an ai and rigidbody to the cube
    - Use the ai to walk along a route set up by waypoints <- This is working properly
    - Use the rigidbody on the cube so that I can get the velocity of the cube <- Not working properly. It is always returning zero.
    - I need the velocity of the cube so that I can tell what direction it is going on the xz axis. I don’t care what direction it is facing, just the direction it is moving towards North, South, East, West.

    This will be used to position the second object at the same position as the cube and play animations depending on what direction the cube is moving. The position works, I just can’t get the velocity to work when using rain. It works with a regular navigation mesh with a nav mesh agent, but not a Rain mesh with a rigidbody.

    I appreciate the help,

    Cyrawnis

    • This topic was modified 7 months ago by  Cyrawnis.
    #39838

    Cyrawnis
    Participant
    void Update()
        {
            if (rb.velocity.x == 0)
            {
                // Play animation 
            }
            else if (rb.velocity.z > .5f)
            {
                // Play animation
            }
            else if (rb.velocity.z < -.5f)
            {
                // Play animation 
            }
            else if (rb.velocity.x > .5f)
            {
                // Play animation 
            }
            else if (rb.velocity.x < -.5f)
            {
                // Play animation 
            }
        }
    • This reply was modified 7 months ago by  Cyrawnis.
    #39848

    Sigil
    Keymaster

    RAIN doesn’t modify the velocity of the rigid body to move as it goes, it uses direct movement (just sets the position on the object’s transform).

    You can get the velocity from the AI though:

    public void Update()
    {
       // Probably should be in Start instead
       RAIN.Core.AIRig tRig = GetComponentInChildren<RAIN.Core.AIRig>();
       // Depending on when you call this (via Update, or LateUpdate, or wherever) 
       // one of these should be right
       Vector3 tPriorVelocity = tRig.AI.Kinematic.PriorVelocity;
       Vector3 tVelocity = tRig.AI.Kinematic.Velocity;
       // Do stuff
    }
    #39863

    Cyrawnis
    Participant

    @Sigil,

    Thank you very much, this really helped a lot with pointing me in the right direction for my research!

    #39864

    Cyrawnis
    Participant

    @Sigil,

    I’ve implemented your method into my code and it’s drastically improved my performance!

    I’m talking 15 fps with 10 enemies in game and now I keep a solid 173 with over 60 enemies!

    This includes all Rain pathfinding and behavioral scripts.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.