public override void _PhysicsProcess(float delta)
 {
     for (int i = 0; i < body.GetSlideCount(); i++)
     {
         var  collision = body.GetSlideCollision(i);
         Node node      = (Spatial)collision.Collider;
         if (node.Name == target.Name)
         {
             NotifyAll(reward);
             agent.AddReward(reward, this, endEpisodeInSuccess);
         }
     }
 }
        public override float[] GetFloatArrayValue()
        {
            List <float> codes = new List <float>();

            for (int i = 0; i < body.GetSlideCount(); i++)
            {
                var  collision = body.GetSlideCollision(i);
                Node node      = (Spatial)collision.Collider;
                if (codeByGroup)
                {
                    var groups = node.GetGroups();
                    foreach (string g in groups)
                    {
                        if (nameCode.ContainsKey(g))
                        {
                            codes.Add(nameCode[g]);
                        }
                        else
                        {
                            codes.Add(1);
                        }
                    }
                }
                else
                {
                    if (nameCode.ContainsKey(node.Name))
                    {
                        codes.Add(nameCode[node.Name]);
                    }
                    else
                    {
                        codes.Add(1);
                    }
                }
            }
            float[] r = new float[shape[0]];
            for (int i = 0; i < codes.Count; i++)
            {
                r[i] = codes[i];
                if (i >= shape[0])
                {
                    break;
                }
            }

            return(r);
        }
Beispiel #3
0
    public override void Process(float delta)
    {
        //This sort of initialisation needs a refactor, but suffices for now.
        if (frameNum == 2)
        {
            // Initialise things that need to wait for emitting signals here.
            // To give other components a chance to set up and fire.

            // get all objects that start in range which could not fire the signals
            Array bodies = area.GetOverlappingBodies();

            foreach (PhysicsBody body in bodies)
            {
                if (IsWatching(body))
                {
                    parent.SendMessage("objectInRange", body);
                }
            }


            frameNum++;
        }
        else if (frameNum == 1)
        {
            // Initialise things that rely on emitting custom signals here.
            frameNum++;
        }
        else if (frameNum == 0)
        {
            frameNum++;
        }

        velocity.x  = direction.x * speed * delta;
        velocity.z  = direction.y * speed * delta;
        velocity.y -= gravity * delta;

        if (velocity.y < -terminal)
        {
            velocity.y = -terminal;
        }

        Vector3 newVelocity = body.MoveAndSlide(velocity, new Vector3(0.0f, 1.0f, 0.0f));

        float xDif = Math.Abs(velocity.x - newVelocity.x);
        float zDif = Math.Abs(velocity.z - newVelocity.z);

        if (xDif > terrainInterferenceEpsilon || zDif > terrainInterferenceEpsilon)
        {
            parent.SendMessage("terrainInterference");
        }

        int numCollisions = body.GetSlideCount();

        for (int i = 0; i < numCollisions; i++)
        {
            parent.SendMessage("collided", body.GetSlideCollision(i));
        }

        if (tojump)
        {
            velocity.y = jumpMagnitude;
            tojump     = false;
        }
        else
        {
            velocity.y = newVelocity.y;
        }
    }