News Forums RAIN General Discussion and Troubleshooting Modifying move speed through code

Tagged: , , , ,

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

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

    Nakor
    Participant

    Hi,

    I have been trying to modify move speed through my code but I can’t seem to get it to do anything.

    This is the code I have been trying to work with. I have also tried changing the default speed with no result there either.

    
    RAIN.Core.AIRig rig = RAIN.Core.AIRig.FindRig(gameObject);
    rig.AI.Motor.Speed -= slowedByAmount;
    

    This does nothing. Not a thing. I’m not sure why exactly, which of course is why I’m posting this

    #25679

    CodersExpo
    Participant

    My guess is you have a Move Node with speed defined there too. This will override the default value set in the Rig. You might use a variable in the Move node “Speed” field and modify that using ai working memory instead. Let me know if you need more help with this.

    #25686

    Nakor
    Participant

    Ah yes, I hadn’t thought of that. I will look into it and let you know how it goes. Thank you.

    #25687

    Nakor
    Participant

    Ok that worked out well. Thanks again. For anyone who may search for this in the future I am posting the code I used to figure this out:

    float curSpeed = rig.AI.WorkingMemory.GetItem<float>("enemyMoveSpeed");
    Debug.Log("_lookit Speed is now(before):  " + curSpeed);
    Debug.Log("_lookit Slowing by:  " + slowedByAmount);
    float newSpeed = curSpeed - slowedByAmount;
    rig.AI.WorkingMemory.SetItem("enemyMoveSpeed", newSpeed);
    curSpeed = rig.AI.WorkingMemory.GetItem<float>("enemyMoveSpeed");
    Debug.Log("_lookit Speed is now(after):  " + curSpeed);
    #25688

    CodersExpo
    Participant

    Thank you for the detailed follow up. I have no doubt this will help others! Glad I could help.

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

You must be logged in to reply to this topic.