News Forums RAIN General Discussion and Troubleshooting RAIN overriding my custom rotation commands

This topic contains 5 replies, has 2 voices, and was last updated by  prime 8 months, 2 weeks ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #33576

    Cedo
    Participant

    I am trying to make the ai turn only in 90 degree increments while moving normally. I have tryed using 2 different move actions on behaivor tree, but when i set moveaction to 0 rotation speed rotation action cant rotate it and if rotation actions speed is set to 0 move action cant move it. Allso if i try to rotate the ai from the custom action when the rotation speed is set 0 on move action it does not work.
    Allso can I get the location in code on where the ai is currently moving to?(not the final destination, for example if destination is behind a wall then its next rally point to final desitantion).
    Here is my code to rotate the ai.

    
    Vector3 targetPos = ai.WorkingMemory.GetItem<Vector3> ("nextPoint");
    	Vector3 relativePosition = ai.Kinematic.Position - targetPos;
    	Quaternion rotationToChek = Quaternion.LookRotation (relativePosition);
    	if (rotationToChek.eulerAngles.y < 50f) 
    	{
    		ai.Kinematic.Rotation = new Vector3 (0,0,0);
    	} 
    	else if (rotationToChek.eulerAngles.y <140f) 
    	{
    		ai.Kinematic.Rotation = new Vector3 (0,90,0);
    	}
    	else if (rotationToChek.eulerAngles.y <230f) 
    	{
    		ai.Kinematic.Rotation = new Vector3 (0,180,0);
    	}
    	else if (rotationToChek.eulerAngles.y <320f) 
    	{
    		ai.Kinematic.Rotation = new Vector3 (0,270,0);
    	}
    	ai.WorkingMemory.SetItem<Vector3> ("rotateTarget", loc);
    
    #33583

    prime
    Keymaster

    What do you mean by “turn in 90 degree increments”? Do you mean that you want it to always finish a turn and end up facing along an axis? Or do you mean that you always want it to “pop” in 90 degree increments and never show the in-between frames?

    AI.Navigator.GetNextPathWaypoint(bool allow3DMovement, bool allowOffGraphMovement, MoveLookTarget cachedMoveLookTarget = null)

    will get you a MoveLookTarget indicating where the AI is trying to go.

    #33585

    Cedo
    Participant

    I want to end up facing along the axis turning several degrees a frame.

    That code that i made was there to test if i can use custom code to make it happen. I know this version of the code will “pop” 90 degree increments and not show in-between frames but its not the end goal.

    #33607

    prime
    Keymaster

    Here’s a clarification that will help your test case. RAIN does not use the word “rotation” to mean the same thing as Unity “rotation”. In RAIN, rotation is a verb. Setting a rotation of 270 means “I want my AI to rotate at 270 degrees per second”. If you are trying to set the direction the AI is facing, then you will want to use ai.Kinematic.Orientation.

    Here’s how I would solve the general problem:
    - Depending on which axis I want to face, I would set a variable in RAIN that represents the axis face angle. Use a custom action to do it, and make sure the custom action runs every frame, just before the Move node.

    //Look along the positive X axis, for example
    ai.WorkingMemory.SetItem<Vector3>("faceTarget", ai.Kinematic.Position + Vector3.right);

    - In the move node, set the Face Target to faceTarget
    - Make sure your Face Before Move Angle is set to 360 on your motor - which allows the AI to be facing any direction when moving

    #33612

    Cedo
    Participant

    Thank you, got it working wey i wanted.

    But if i understand how Motor.FaceBeforeMoveAngle it is suposed to work then it broken a bit. At least for me ai moves while turning, i have it set to 360 “Current face before move angle of the Motor. Angle between the AI and its movement target that the AI must rotate toward before beginning linear movement ” is quote from http://rivaltheory.com/api/html/6c82076c-4700-561a-c24a-82831f4f487b.htm

    • This reply was modified 8 months, 2 weeks ago by  Cedo.
    • This reply was modified 8 months, 2 weeks ago by  Cedo.
    • This reply was modified 8 months, 2 weeks ago by  Cedo.
    #33616

    prime
    Keymaster

    FaceBeforeMoveAngle is the maximum degrees the AI can be turned away from the direction it wants to move. If the angle ever exceeds that, the AI will stop moving and rotate toward the target before it continues.

    Setting the value to 360 will cause the AI to always turn while moving. If that’s not what you want, and you’d like to see the AI turn in place before it moves, then set the value to a very low number (0.01 or similar)

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

You must be logged in to reply to this topic.