Exemplo n.º 1
0
    public void SetMovement(ActorMovement amovement)
    {
        _falling = Vector3.zero;
        _angular = Vector4.zero;

        transform.position = DataBridge.cnv(amovement.Location);
        transform.rotation = DataBridge.cnv(amovement.Rotation);

        _current_region = Common.ToRegion(transform.position, 0);
    }
Exemplo n.º 2
0
    // movement
    public void DecodeMovement(ByteString movement)
    {
        ActorMovement amovement = ActorMovement.Parser.ParseFrom(movement);

        transform.localPosition = DataBridge.cnv(amovement.Location);
        _local_velocity         = DataBridge.cnv(amovement.Velocity);

        transform.localRotation = DataBridge.cnv(amovement.Rotation);
        _local_angular          = DataBridge.cnv(amovement.Angular);

        ConsoleOutput.Trace("AgentMove " + amovement.Angular.W + " @ " + amovement.Angular.Y);
    }
Exemplo n.º 3
0
    public bool ialUpdate(TryAgent agent, Dictionary <int, AgentUtils <TryAgent> .Property> properties)
    {
        AgentUtils <TryAgent> .Property pbasic;
        if (properties.TryGetValue(( int )PTYPE.Basic, out pbasic))
        {
            if (pbasic.updated)
            {
                //Basic abasic = Basic.Parser.ParseFrom( pbasic.data );
                // nothing is allowed to be updated
                ConsoleOutput.Trace("ialUpdate: \"" + agent.id + "\" |Basic " + pbasic.data.Length);
                pbasic.updated = false;
            }
        }

        AgentUtils <TryAgent> .Property pmovement;
        if (properties.TryGetValue(( int )PTYPE.Movement, out pmovement))
        {
            if (pmovement.updated)
            {
                if (null != agent.amove)
                {
                    ConsoleOutput.Trace("ialUpdate: \"" + agent.id + "\" |Movement " + pmovement.data.Length);
                    agent.amove.DecodeMovement(pmovement.data);
                }
                pmovement.updated = false;
            }
        }

        AgentUtils <TryAgent> .Property pscale;
        if (properties.TryGetValue(( int )PTYPE.Scale, out pscale))
        {
            if (pscale.updated)
            {
                ActorScale ascale = ActorScale.Parser.ParseFrom(pscale.data);
                agent.gobj.transform.localScale = DataBridge.cnv(ascale.Scale);
                ConsoleOutput.Trace("ialUpdate: \"" + agent.id + "\" |Scale " + pscale.data.Length);
                pscale.updated = false;
            }
        }
        return(false);
    }
Exemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        float delta_time = Time.deltaTime;

        // update region
        {
            _current_region = Common.ToRegion(transform.position, 0);
        }

        //if( null != _camera_controller)
        {
            // zero movement
            Vector3 movement = Vector3.zero;

            // get input
            float hinput = Input.GetAxis("Horizontal");
            float vinput = Input.GetAxis("Vertical");

            if (0 != hinput || 0 != vinput)
            {
                // get yaw
                float yaw = CameraController.Yaw;
                UnityEngine.Quaternion ryaw = UnityEngine.Quaternion.Euler(0, yaw, 0);

                // get forward and rightward
                Vector3 forward     = ryaw * Vector3.forward;
                Vector3 right       = ryaw * Vector3.right;
                Vector3 target_move = hinput * right + vinput * forward;

                // move
                {
                    movement += target_move * MaxLinearSpeed * Time.deltaTime;
                }

                // rotation
                {
                    UnityEngine.Quaternion target_dir  = UnityEngine.Quaternion.LookRotation(target_move);
                    UnityEngine.Quaternion current_dir = transform.rotation;

                    // To Angle Axis
                    float   delta_angle;
                    Vector3 delta_axis;
                    InnovaMath.ToAngleAxis(current_dir, target_dir, out delta_angle, out delta_axis);

                    float need_time = Mathf.Abs(delta_angle) / MaxAngularSpeed;

                    transform.rotation = UnityEngine.Quaternion.Slerp(transform.rotation, target_dir, Time.deltaTime / need_time);
                    _angular           = new Vector4(delta_axis.x, delta_axis.y, delta_axis.z, delta_angle > 0 ? MaxAngularSpeed : delta_angle < 0 ? -MaxAngularSpeed : 0);
                }
            }
            else
            {
                _angular = Vector4.zero;
            }

            {
                // gravity
                if (false == _character_controller.isGrounded)
                {
                    _falling += Physics.gravity * Time.deltaTime;
                    movement += _falling * Time.deltaTime;
                }
                else
                {
                    _falling = Vector3.zero;
                }

                // move
                _character_controller.Move(movement);
            }

            // let camera follow
            {
                CameraController.LookAtPosition = transform.position;
            }

            // update movement
            {
                ActorMovement new_movement = new ActorMovement();
                new_movement.Location = DataBridge.cnv(transform.localPosition);
                new_movement.Rotation = DataBridge.cnv(transform.localRotation);
                new_movement.Velocity = DataBridge.cnv(_character_controller.velocity);
                new_movement.Angular  = DataBridge.cnv(_angular);

                if (false == new_movement.Equals(_movement))
                {
                    _movement = new_movement;
                    _moved    = true;
                }
                else
                {
                    //_moved = false; // will be set false when getting.
                }
            }
        }
    }