예제 #1
0
    private void OnMovement(InputValue value)
    {
        Vector2 rawInpVec = value.Get <Vector2>();

        //Debug.Log("OnMovement" + rawInpVec);
        MovementEvent?.Invoke(rawInpVec);
    }
    void FixedUpdate()
    {
        frameMovement.sprint = _movement.sprintTime;
        Vector3 tempForce = _movement.ApplyForces(frameMovement.forceNextFrame);

        MovementEvent?.Invoke(frameMovement);
        frameMovement                = new FrameMovement();
        frameMovement.position       = transform.position;
        frameMovement.forceNextFrame = tempForce;
    }
예제 #3
0
 /// <summary>
 /// Sends movement event with ControlledEntity
 /// </summary>
 /// <param name="dir">Direction of movement</param>
 private void MoveEntity(Direction dir)
 {
     MovementEvent?.Invoke(ControlledEntity, dir);
 }
예제 #4
0
    private void UpdateState()
    {
        Velocity     = (transform.position - prevPosition) / Time.fixedDeltaTime;
        prevPosition = transform.position;

        if (onGround)
        {
            if (MoveState == MovementState.Jumping || MoveState == MovementState.Falling)
            {
                OnLanding?.Invoke(this);
            }

            if (Velocity.magnitude > 0.1f && MoveState != MovementState.Moving)
            {
                MoveState = MovementState.Moving;
                OnMoving?.Invoke(this);
            }
            else if (Velocity.magnitude <= 0.1f && MoveState != MovementState.Idle)
            {
                MoveState = MovementState.Idle;
                OnIdle?.Invoke(this);
            }
            changeStateTimer = 0;
            FallingSpeed     = 0;
        }
        else if (!onGround && steepContactCount > 0)
        {
            if (MoveState == MovementState.Jumping || MoveState == MovementState.Falling)
            {
                OnLanding?.Invoke(this);
            }

            if (MoveState != MovementState.Sliping)
            {
                MoveState = MovementState.Sliping;
                OnSliping?.Invoke(this);
            }
            changeStateTimer = 0;
            FallingSpeed     = 0;
        }
        else if (!onGround && steepContactCount <= 0)
        {
            if (Velocity.y < 0.5f && MoveState != MovementState.Falling)
            {
                changeStateTimer += Time.fixedDeltaTime;
                if (changeStateTimer >= 0.5f)
                {
                    MoveState = MovementState.Falling;
                    OnFalling?.Invoke(this);
                    changeStateTimer = 0;
                }
            }
            else
            {
                changeStateTimer = 0;
            }
            if (Velocity.y >= 0.5f && MoveState != MovementState.Jumping && isJumping)
            {
                MoveState = MovementState.Jumping;
                OnJumping?.Invoke(this);
            }


            if (FallingSpeed > Velocity.y)
            {
                FallingSpeed = Velocity.y;
            }
            if (Velocity.y >= 0)
            {
                FallingSpeed = 0;
            }
        }
    }
예제 #5
0
 protected override void Move(float x, float y)
 {
     CursorMoveEvent.Invoke(new Vector2(x, y));
 }
    public void UpdateFromRecordedMovement(FrameMovement frameMovement)
    {
        _head.rotation = frameMovement.look;
        if (grabFrameBuffer > 0 || frameMovement.grab)
        {
            if (_grabber.Grab())
            {
                grabFrameBuffer = 0;
            }
            else
            {
                --grabFrameBuffer;
            }
        }
        if (frameMovement.release)
        {
            if (_grabber.Release())
            {
                grabFrameBuffer = 0;
            }
        }

        SetAnimatorValues(frameMovement.hMov, frameMovement.vMov);

        /*
         * if (frameMovement.jump) _movement.Jump();
         * _movement.sprintTime = frameMovement.sprint;
         * _movement.ApplyForces(frameMovement.forceNextFrame);
         *
         * if (Vector3.Distance(transform.position, frameMovement.position) < 0.1f)
         * {
         *  transform.position = frameMovement.position;
         * }
         * else
         * {
         *  Debug.Log(name + " desynced!");
         * }
         */

        if (synced && frameMovement.jump && !_feet.isGrounded && _movement.jumping)
        {
            //synced = false;
            Debug.Log(name + " desynced!");
        }

        if (synced)
        {
            _movement.Move(frameMovement.position);
        }
        else
        {
            if (frameMovement.jump)
            {
                _movement.Jump();
            }
            _movement.sprintTime = frameMovement.sprint;
            _movement.ApplyForces(frameMovement.forceNextFrame);
        }

        MovementEvent?.Invoke(frameMovement);
    }
예제 #7
0
 private void RaiseMovementEvent(int entity, Direction dir)
 {
     MovementEvent?.Invoke(entity, dir);
 }