News Forums RAIN General Discussion and Troubleshooting Change the value "Speed" through a script.

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

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #37573

    Zeitlan
    Participant

    Hi, I explain :
    I just want to change the value Speed of the Motor of my AI.
    My PatrolRoute works, I have the value that I send with my Arduino but I don’t know how to change the value speed according to the Arduino’s value.
    I’m using an Arduino and i try this :

    using RAIN.Action;
    using RAIN.Motion;
    using System.Collections;
    using System.IO.Ports;
    using UnityEngine;
    public class WALLAH : MonoBehaviour {
    	private AIRig _aiRig = null;
    	SerialPort sp = new SerialPort("COM5",9600);
    	void Start () {
    		sp.Open ();
    		_aiRig = GetComponentInChildren<AIRig>();
    	}
    	void Update () {
    		if(sp.IsOpen)
    		{
    			try
    			{	
    				MoveObject(sp.ReadByte());
    				print(sp.ReadByte());
    			}
    			catch(System.Exception)
    			{
    			}
    		}
    	}
    	void MoveObject(int vitesse)
    	{
    		_aiRig.AI.Motor.Speed = vitesse;
    	}
    }

    And the value doesn’t change.
    Thank you for answers.

    #37574

    Zeitlan
    Participant

    Solved, i don’t add the value on the “Memory”

    #37578

    prime
    Keymaster

    Setting the speed directly on the motor doesn’t necessarily help. The Behavior Tree Move node will reset the speed on its own, either to the speed specified in the node or to the DefaultSpeed of the motor.

    If you call Move manually on the motor, then it will obey whatever Speed value you set (or was most recently set).

    Sounds like maybe you are now setting the arduino value into an AI Memory variable, and then using that variable to represent speed in your move node? That would work.

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

You must be logged in to reply to this topic.