Ejemplo n.º 1
0
    //Rotate camera toward '_direction', at the rate of '_speed', around the upwards vector of this gameobject;
    public void RotateTowardsVelocity(Vector3 _velocity, float _speed)
    {
        //Remove any unwanted components of direction;
        _velocity = VectorMath.RemoveDotVector(_velocity, GetUpDirection());

        //Calculate angle difference of current direction and new direction;
        float _angle = VectorMath.GetAngle(GetFacingDirection(), _velocity, GetUpDirection());

        //Calculate sign of angle;
        float _sign = Mathf.Sign(_angle);

        //Calculate final angle difference;
        float _finalAngle = Time.deltaTime * _speed * _sign * Mathf.Abs(_angle / 90f);

        //If angle is greater than 90 degrees, recalculate final angle difference;
        if (Mathf.Abs(_angle) > 90f)
        {
            _finalAngle = Time.deltaTime * _speed * _sign * ((Mathf.Abs(180f - Mathf.Abs(_angle))) / 90f);
        }

        //Check if calculated angle overshoots;
        if (Mathf.Abs(_finalAngle) > Mathf.Abs(_angle))
        {
            _finalAngle = _angle;
        }

        //Take movement speed into account by comparing it to 'maximumMovementSpeed';
        _finalAngle *= Mathf.InverseLerp(0f, maximumMovementSpeed, _velocity.magnitude);

        RotateCamera(_finalAngle, 0f);
    }
    void LateUpdate()
    {
        //Get controller velocity;
        Vector3 _velocity = controller.GetVelocity();

        //Project velocity onto a plane defined by the 'up' direction of the parent transform;
        _velocity = Vector3.ProjectOnPlane(_velocity, parentTransform.up);

        float _magnitudeThreshold = 0.001f;

        //If the velocity's magnitude is smaller than the threshold, return;
        if (_velocity.magnitude < _magnitudeThreshold)
        {
            return;
        }

        //Normalize velocity direction;
        _velocity.Normalize();

        //Get current 'forward' vector;
        Vector3 _currentForward = tr.forward;

        //Calculate (signed) angle between velocity and forward direction;
        float _angleDifference = VectorMath.GetAngle(_currentForward, _velocity, parentTransform.up);

        //Calculate angle factor;
        float _factor = Mathf.InverseLerp(0f, fallOffAngle, Mathf.Abs(_angleDifference));

        //Calculate this frame's step;
        float _step = Mathf.Sign(_angleDifference) * _factor * Time.deltaTime * turnSpeed;

        //Clamp step;
        if (_angleDifference < 0f && _step < _angleDifference)
        {
            _step = _angleDifference;
        }
        else if (_angleDifference > 0f && _step > _angleDifference)
        {
            _step = _angleDifference;
        }

        //Add step to current y angle;
        currentYRotation += _step;

        //Clamp y angle;
        if (currentYRotation > 360f)
        {
            currentYRotation -= 360f;
        }
        if (currentYRotation < -360f)
        {
            currentYRotation += 360f;
        }

        //Set transform rotation using Quaternion.Euler;
        tr.localRotation = Quaternion.Euler(0f, currentYRotation, 0f);
    }
Ejemplo n.º 3
0
        public void RotateAngle(PointF p)
        {
            MultiSelection.ForEach(s =>
            {
                Vector startVect = VectorMath.GetVector(s.MedianPoint, LastLocation);
                Vector endVect   = VectorMath.GetVector(s.MedianPoint, p);

                float angle = VectorMath.GetAngle(startVect, endVect);
                s.Rotate(angle);
            });

            LastLocation = p;
        }
Ejemplo n.º 4
0
    //Rotate the camera toward a look vector in the scene;
    public void RotateTowardDirection(Vector3 _direction, float _lookSpeed)
    {
        //Normalize direction;
        _direction.Normalize();

        //Transform target look vector to this transform's local space;
        _direction = tr.parent.InverseTransformDirection(_direction);

        //Calculate (local) current look vector;
        Vector3 _currentLookVector = GetAimingDirection();

        _currentLookVector = tr.parent.InverseTransformDirection(_currentLookVector);

        //Calculate x angle difference;
        float _xAngleDifference = VectorMath.GetAngle(new Vector3(0f, _currentLookVector.y, 1f), new Vector3(0f, _direction.y, 1f), Vector3.right);

        //Calculate y angle difference;
        _currentLookVector.y = 0f;
        _direction.y         = 0f;
        float _yAngleDifference = VectorMath.GetAngle(_currentLookVector, _direction, Vector3.up);

        //Turn angle values into Vector2 variables for better clamping;
        Vector2 _currentAngles   = new Vector2(currentXAngle, currentYAngle);
        Vector2 _angleDifference = new Vector2(_xAngleDifference, _yAngleDifference);

        //Calculate normalized direction;
        float _angleDifferenceMagnitude = _angleDifference.magnitude;

        if (_angleDifferenceMagnitude == 0f)
        {
            return;
        }
        Vector2 _angleDifferenceDirection = _angleDifference / _angleDifferenceMagnitude;

        //Check for overshooting;
        if (_lookSpeed * Time.deltaTime > _angleDifferenceMagnitude)
        {
            _currentAngles += _angleDifferenceDirection * _angleDifferenceMagnitude;
        }
        else
        {
            _currentAngles += _angleDifferenceDirection * _lookSpeed * Time.deltaTime;
        }

        //Set new angles;
        currentYAngle = _currentAngles.y;
        //Clamp vertical rotation;
        currentXAngle = Mathf.Clamp(_currentAngles.x, -upperVerticalLimit, lowerVerticalLimit);

        UpdateRotation();
    }
Ejemplo n.º 5
0
        public void Update(SceneContext c, GameTime gt)
        {
            if (c.IsFlagSetOR(GameFlagMask.CROSSHAIR_HIDE_MASK))
            {
                pj.WorldAnchorB = this.FocusedEntity.Mesh.Body.Position;
                return;
            }



            float dx = 0;
            float dy = 0;

            //InputConfig ic = InputConfig.Instance;
            //if (ic.RIGHT_AXIS.WasMoved)
            //{
            //    dx = ic.RIGHT_AXIS.DX;
            //    dy = ic.RIGHT_AXIS.DY;
            //}
            //else
            //{
            //    dx = ic.MOUSE.DX;
            //    dy = ic.MOUSE.DY;
            //}


            foreach (Axis a in this.ListeningAxis)
            {
                if (a.WasMoved)
                {
                    dx = a.DX;
                    dy = a.DY;
                    break;
                }
            }

            //   // Ray berechnen -> das ist die richtung/bahn auf der projektiele fliegen werden -> wird vom offsetpunkt an berechnet
            CursorDirection = this.FocusedEntity.Mesh.Body.Position - this.Sensor.Position; //Vector2.Subtract(actorData.RightHandOffset, new Vector2(this.X, this.Y));
            CursorDirection.Normalize();
            CursorDirection = Vector2.Negate(CursorDirection);


            // player rotation setzen
            float bodyAngle = this.FocusedEntity.Mesh.Body.Rotation;

            float desiredAngle = -VectorMath.GetAngle(CursorDirection);



            float speed = this.FocusedEntity.GetAttribute <ActorDataAttribute>().RotationSpeed;

            /// source: http://www.iforce2d.net/b2dtut/rotate-to-angle
            float nextAngle     = bodyAngle + this.FocusedEntity.Mesh.Body.AngularVelocity / speed;
            float totalRotation = desiredAngle - nextAngle;

            while (totalRotation < -180 * DEGTORAD)
            {
                totalRotation += 360 * DEGTORAD;
            }
            while (totalRotation > 180 * DEGTORAD)
            {
                totalRotation -= 360 * DEGTORAD;
            }
            float desiredAngularVelocity = totalRotation * speed;

            float torque = this.FocusedEntity.Mesh.Body.Inertia * desiredAngularVelocity / (1 / speed);

            this.FocusedEntity.Mesh.Body.ApplyTorque(torque);


            // position:
            this.relativePos -= ConvertUnits.ToSimUnits(new Vector2(dx, dy) * CursorSensitivity);

            if (VectorMath.Distance(new Vector2(), this.relativePos) >= ConvertUnits.ToSimUnits(this.CursorRange))
            {
                //nicht die ray nemen, sondern vom mittelpunkt des spielers ausgehen
                Vector2 rangeDir = this.relativePos;
                rangeDir.Normalize();

                this.relativePos = rangeDir * ConvertUnits.ToSimUnits(this.CursorRange);
            }

            pj.WorldAnchorB = this.FocusedEntity.Mesh.Body.Position + this.relativePos;


            foreach (ICrosshairDrawableProcessor dp in this.drawableProcessor)
            {
                dp.Update(c, gt);
            }

            // Update Tool
            if (this.SelectedTool != null)
            {
                if (this.PrimaryAction.WasPressed)
                {
                    this.SelectedTool.OnPrimaryDown(c);
                }

                if (this.PrimaryAction.WasReleased)
                {
                    this.SelectedTool.OnPrimaryUp(c);
                }

                if (this.SecondaryAction.WasPressed)
                {
                    this.SelectedTool.OnSecondaryDown(c);
                }

                if (this.SecondaryAction.WasReleased)
                {
                    this.SelectedTool.OnSecondaryUp(c);
                }

                this.SelectedTool.Update(c, gt);
            }
        }
Ejemplo n.º 6
0
    private void LateUpdate()
    {
        bool _isGrounded = controller.IsGrounded();
        //set animation isgrounded, _isgrounded

        Vector3 _movementVelocity = controller.GetMovementVelocity();

        if (!config.isImposter)
        {
            config.humanAnimator.SetFloat("TotalMovementSpeed", _movementVelocity.magnitude);
        }
        else
        {
            config.monsterAnimator.SetFloat("TotalMovementSpeed", _movementVelocity.magnitude);
        }

        //Smooth movement
        currentMovementVelocity = Vector3.Lerp(currentMovementVelocity, _movementVelocity, Time.deltaTime * smoothingLerpValue);

        //Smooth hand blending
        if (!config.isImposter)
        {
            switch (fightController.selectedWeapon)
            {
            case Player_FightingController.Weapon.Fists:
                config.humanHandsAnimator.SetFloat("TotalMovementSpeed", currentMovementVelocity.magnitude);
                break;

            case Player_FightingController.Weapon.Knife:
                config.humanStabAnimator.SetFloat("TotalMovementSpeed", currentMovementVelocity.magnitude);
                break;

            case Player_FightingController.Weapon.Pistol:
                config.humanPistolAnimator.SetFloat("TotalMovementSpeed", currentMovementVelocity.magnitude);
                break;
            }
        }
        else
        {
            config.monsterHandsAnimator.SetFloat("TotalMovementSpeed", currentMovementVelocity.magnitude);
        }

        float _forwardSpeed  = VectorMath.GetDotProduct(currentMovementVelocity, characterMeshTransform.forward);
        float _sidewardSpeed = VectorMath.GetDotProduct(currentMovementVelocity, characterMeshTransform.right);

        if (!config.isImposter)
        {
            config.humanAnimator.SetFloat("ForwardSpeed", _forwardSpeed);
            config.humanAnimator.SetFloat("SidewardSpeed", _sidewardSpeed);
        }
        else
        {
            config.monsterAnimator.SetFloat("ForwardSpeed", _forwardSpeed);
            config.monsterAnimator.SetFloat("SidewardSpeed", _sidewardSpeed);
        }
        Vector3 _momentum = controller.GetMomentum();

        //smooth momentum
        currentMomentum = Vector3.Lerp(currentMomentum, _momentum, Time.deltaTime * smoothingLerpValue);

        float _verticalSpeed = VectorMath.GetDotProduct(currentMomentum, characterMeshTransform.up);
        //animator setfloat speedvertical, _verticalspeed

        //Turning
        Vector3 _newMeshDir = characterMeshTransform.forward;
        float   _angle      = VectorMath.GetAngle(_newMeshDir, characterMeshDir, characterMeshTransform.up);
        float   _turnSpeed  = 0f;

        if (Time.deltaTime != 0f)
        {
            _turnSpeed = _angle / Time.deltaTime;
        }

        //smoothing
        currentTurnSpeed = Mathf.Lerp(currentTurnSpeed, _turnSpeed, Time.deltaTime * smoothingLerpValue);
        characterMeshDir = _newMeshDir;

        if (!config.isImposter)
        {
            config.humanAnimator.SetFloat("TurnSpeed", currentTurnSpeed);
        }
        else
        {
            config.monsterAnimator.SetFloat("TurnSpeed", currentTurnSpeed);
        }

        //attacking timer reset
        //this small interval plays animation decently.. prob can be done better lol
        if (config.isImposter)
        {
            if (config.monsterAnimator.GetBool("IsPunching"))
            {
                if (punchTimerCounter <= punchTimer)
                {
                    punchTimerCounter += 1 * Time.deltaTime;
                }
                else
                {
                    punchTimerCounter = 0;
                    config.monsterAnimator.SetBool("IsPunching", false);
                }
            }
        }
        else
        {
            //this small interval plays animation decently.. prob can be done better lol
            if (config.humanAnimator.GetBool("IsPunching"))
            {
                if (punchTimerCounter <= punchTimer)
                {
                    punchTimerCounter += 1 * Time.deltaTime;
                }
                else
                {
                    punchTimerCounter = 0;
                    config.humanAnimator.SetBool("IsPunching", false);
                }
            }
        }
    }