void FixedUpdate()
    {
        Vector3 m_Input = Camera.main.transform.forward * Input.GetAxis("Vertical") + Camera.main.transform.right * Input.GetAxis("Horizontal");

        m_Input.y = 0;
        m_Input.Normalize();
        rigidbody.MovePosition(transform.position + m_Input * Time.deltaTime * speed);
        if (m_Input.sqrMagnitude > 10e-10)
        {
            rigidbody.MoveRotation(Quaternion.LookRotation(m_Input));
        }

        animator.SetFloat("Speed", rigidbody.velocity.magnitude / speed);
        RaycastHit hit;

        if (!rigidbody.SweepTest(Vector3.down, out hit))
        {
            animator.SetBool("Grounded", false);
            rigidbody.MovePosition(transform.position + Vector3.down * Time.deltaTime * fallSpeed);
        }
        else
        {
            TipToePlatform tipToePlatform = hit.collider.GetComponent <TipToePlatform>();
            if (tipToePlatform != null)
            {
                tipToePlatform.CharacterTouches();
            }
            animator.SetBool("Grounded", true);
        }

        if (transform.position.y < -10)
        {
            ResetPosition();
        }
    }
Beispiel #2
0
    // Start is called before the first frame update
    void Start()
    {
        float             platformWidth = (areaWidth - (width - 1) * spacing) / width;
        float             platformDepth = (areaDepth - (depth - 1) * spacing) / depth;
        ISet <Vector2Int> path          = GeneratePath(width, depth);

        for (int zIndex = 0; zIndex < depth; zIndex++)
        {
            for (int xIndex = 0; xIndex < width; xIndex++)
            {
                GameObject platform = Instantiate(platformPrefab, transform);
                platform.transform.localPosition = new Vector3(
                    -areaWidth / 2 + platformWidth / 2 + xIndex * (platformWidth + spacing),
                    0,
                    -areaDepth / 2 + platformDepth / 2 + zIndex * (platformDepth + spacing));
                platform.transform.localScale = new Vector3(platformWidth, 1, platformDepth);
                TipToePlatform tipToePlatform = platform.GetComponent <TipToePlatform>();
                tipToePlatform.isPath = path.Contains(new Vector2Int(xIndex, zIndex));
            }
        }
    }