#DiscreteAction Hold Jump

1 messages · Page 1 of 1 (latest)

sharp frigate
#

HI! I'm doing this little 3D project to understand how ML-Agents works and then expand it and make a nice training environment.
However, I am having some problems with the coding and settings of Unity.

This is the code:
` private void Jump()
{
//Button was just pushed
if (Input.GetKeyDown(KeyCode.Space) && OnGround)
{
isJumping = true;
JumpTimeCounter = JumpTime;
CubeRigidbody.velocity = new Vector3(CubeRigidbody.velocity.z, JumpForce);
Debug.Log("Spazio premuto");
OnGround = false;
}

    //Button is being held
    if (Input.GetKey(KeyCode.Space))
    {
        if (JumpTimeCounter > 0 && isJumping)
        {
            CubeRigidbody.velocity = new Vector3(CubeRigidbody.velocity.z, JumpForce);
            Debug.Log("Spazio mantenuto");
            JumpTimeCounter -= Time.deltaTime;
        }
        else
        {
            isJumping = false;
        }
    }

    //Button war releared
    if (Input.GetKeyUp(KeyCode.Space))
    {
        isJumping = false;
        Debug.Log("Spazio rilasciato");
    }
}`

I want to create a system with ML-Agent that do this same thing (hold Jump super mario like)

sharp frigate
#

DiscreteAction HOld Jump

sharp frigate
#

DiscreteAction Hold Jump

lament bloom
#

what's the question? there's nothing here that relates to the agent input
you can jump (i.e. simulate the space being pressed) while a discrete action is > 0

sharp frigate
#

I'm new to unity and ML-Agent and I wouldn't know how to convert a system like this using ML-Agent
For now I've only managed to make a standard jump script

lament bloom
#

well you need to make your script inherit from Agent and then override the OnActionReceived method so you can get the discrete actions from the agent

#

the demos are a good place to start

#

basically instead of
if input.getkeyup(keycode.space)
you'll do something like
if actions.discreteaction[0] == 1
but like i say, needs to be inside the onactionreceived method
it'll make more sense when you look at the demos

sharp frigate
# lament bloom the demos are a good place to start

I do not know if I saw bad, but in the demos I saw no examples to set a jump kept (as those of super mario) I saw only classic jumps in fact I had more or less managed to do it.
Missing the way to make it jump as if holding the key down

#

I will try to better check the demos maybe I missed some explanatory example

lofty walrus
# sharp frigate I do not know if I saw bad, but in the demos I saw no examples to set a jump kep...

I think he meant just how it works in general, not specifically your issue. Btw, the ai will output a value every step (basically a frame) for each action, so a discreate action of either 0 or 1, with 0 representing not pressing spacebar and 1 representing pressing the spacebar, will work with the same logic as just checking if the spacebar is pressed. So, like smallg said, you can probably just replace

if input.getkeyup(keycode.space)
with
if actions.discreteaction[0] == 1