コード例 #1
0
        private Task OnCheckpointPlacementPreview()
        {
            // Don't render the checkpoint preview.
            if (!creatorState.OptionPreview)
            {
                return(Task.FromResult(0));
            }

            // Calculate the position of the marker.
            float checkpointDistance = 10.0f;

            if (creatorState.ZFix)
            {
                GameTask(async() =>
                {
                    Vector3 markerPosition = commonState.LocalPlayerPosition + (commonState.LocalPlayerDirections[0] * checkpointDistance);
                    checkpointLastPosition = await GroundHelper.PositionOnGround(markerPosition);
                });
            }
            else
            {
                checkpointLastPosition = commonState.LocalPlayerPosition + (commonState.LocalPlayerDirections[0] * checkpointDistance);
            }

            RenderCheckpoint();
            return(Task.FromResult(0));
        }
コード例 #2
0
ファイル: RaceCheckpoint2.cs プロジェクト: eFFecTM/ssc-race
        public async Task Render()
        {
            if (GroundPosition == Vector3.Zero)
            {
                GroundPosition = await GroundHelper.PositionOnGround(Position);
            }

            Color col = Color.FromArgb(255, 250, 220, 94);

            World.DrawMarker(MarkerType.VerticalCylinder, GroundPosition, Vector3.Up, Vector3.Zero, 5.0f * Vector3.One, col);
        }
コード例 #3
0
    void FixedUpdate()
    {
        float inputX = Input.GetAxis("Horizontal");
        float inputY = Input.GetAxis("Vertical");

        Vector3 nextGroundNormal = GroundHelper.GetGroundNormalBelowSphere(transform.position, Vector3.down, radius);

        groundNormal = Vector3.RotateTowards(groundNormal, nextGroundNormal, 90 * Time.fixedDeltaTime, 1);

        switch (movementForward)
        {
        case ForwardType.CAMERA:
        {
            fwd   = cam.transform.forward;
            right = cam.transform.right;
        }
        break;

        case ForwardType.AVATAR:
        {
            fwd   = transform.forward;
            right = transform.right;
        }
        break;
        }

        Vector3 fwdOnFlatPlane = Vector3.ProjectOnPlane(fwd, Vector3.up);

        fwd = Vector3.ProjectOnPlane(fwdOnFlatPlane, groundNormal);

        Vector3 rightOnFlatPlane = Vector3.ProjectOnPlane(right, Vector3.up);

        right = Vector3.ProjectOnPlane(rightOnFlatPlane, groundNormal);
        // ou
        //right = Vector3.Cross(groundNormal, fwd);

        Vector3 mvtDirection = inputX * right + inputY * fwd;

        mvtDirection.Normalize();

        Vector3 targetPosition = rb.position + mvtDirection * speed * Time.fixedDeltaTime;

        targetPosition = HandleMovementCollision(targetPosition);
        rb.MovePosition(targetPosition);

        if (alignUpWithSlope)
        {
            transform.rotation = Quaternion.LookRotation(fwd, groundNormal);
        }
    }
コード例 #4
0
    void FixedUpdate()
    {
        float inputX = Input.GetAxis("Horizontal");
        float inputY = Input.GetAxis("Vertical");

        // no dragwhenMoving
        if (inputX != 0 || inputY != 0)
        {
            rb.drag = 0;
        }
        else
        {
            rb.drag = drag;
        }
        // ou
        // Vector2 dir = new Vector2(inputX, inputY).normalized;
        // rb.drag = (1 - Vector2.Dot(dir, dir)) * drag;

        // compute movement direction
        Vector3 mvtDirection = Vector3.zero;

        switch (testCase)
        {
        case TestCase.USE_NOTHING:
            mvtDirection = inputX * cam.transform.right + inputY * cam.transform.forward;
            break;

        case TestCase.PROJECT_ON_GROUND_PLANE:
        { // ici les accolades sont nécessaire pour éviter des erreurs de redéclaration des variables camFwd et camRight
            camFwd       = Vector3.ProjectOnPlane(cam.transform.forward, Vector3.up);
            camRight     = Vector3.ProjectOnPlane(cam.transform.right, Vector3.up);
            mvtDirection = inputX * camRight + inputY * camFwd;
        }
        break;

        case TestCase.PROJECT_ON_GROUND_TERRAIN:
        {
            // TODO
        }
        break;

        case TestCase.PROJECT_ON_GROUND_MESH:
        {
            Vector3 nextGroundNormal = GroundHelper.GetGroundNormalBelowSphere(transform.position, Vector3.down, transform.lossyScale.magnitude * 0.5f);
            groundNormal = Vector3.RotateTowards(groundNormal, nextGroundNormal, 10 * Time.fixedDeltaTime, 1);


            Vector3 fwdOnFlatPlane = Vector3.ProjectOnPlane(cam.transform.forward, Vector3.up);
            camFwd = Vector3.ProjectOnPlane(fwdOnFlatPlane, groundNormal);

            Vector3 rightOnFlatPlane = Vector3.ProjectOnPlane(cam.transform.right, Vector3.up);
            camRight = Vector3.ProjectOnPlane(rightOnFlatPlane, groundNormal);
            // ou
            //camRight = Vector3.Cross(groundNormal, camFwd);

            mvtDirection = inputX * camRight + inputY * camFwd;

            transform.rotation = Quaternion.LookRotation(camFwd, groundNormal);
        }
        break;
        }

        mvtDirection.Normalize();
        rb.AddForce(mvtDirection * accel);
        rb.velocity = Vector3.ClampMagnitude(rb.velocity, maxSpeed);
    }