Ejemplo n.º 1
0
    private void Start()
    {
        var l = TSPhysics.RaycastAll(TSVector.up * 10, (TSVector.one), out TSRaycastHit[] hit, 2);

        Debug.DrawLine(Vector3.up * 10, Vector3.up * 10 + Vector3.one * 2, Color.red, 100);
        //Debug.Log(l);
        foreach (var item in hit)
        {
            //Debug.DrawLine(Vector3.up * 10, item.point.ToVector(), Color.red, 100);
            Debug.LogError(item.point + " || " + item.transform.name);
        }

        //var tmp = TSPhysics.Raycast(TSVector.up * 15, (TSVector.down), out TSRaycastHit hit, 100);
        //if (tmp)
        //{
        //    Debug.DrawLine(Vector3.up * 15, hit.point.ToVector(), Color.red, 100);
        //    Debug.Log(hit.transform.name);
        //}
    }
Ejemplo n.º 2
0
    public void FixedUpdate()
    {
        this.wheelAngle = TSMath.Lerp(this.wheelAngle, this.steerAngle, Time.fixedDeltaTime * this.steerTime);
        if (TSPhysics.Raycast(transform.position.ToTSVector(), (-transform.up).ToTSVector(), out TSRaycastHit hit, maxLength + wheelRadius))
        {
            lastLength     = springLength;
            springLength   = hit.distance.AsFloat() - wheelRadius;
            springLength   = TSMath.Clamp(springLength, minLength, maxLength).AsFloat();
            springVelocity = (lastLength - springLength) / Time.fixedDeltaTime;
            springForce    = springStiffness * (restLength - springLength);
            damperForce    = damperStiffness * springVelocity;

            suspensionForce = (springForce + damperForce) * transform.up.ToTSVector();

            this.wheelVelocityLS = this.tsTransform.InverseTransformDirection(this.trb.GetPointVelocity(hit.point));

            this.Fx = Input.GetAxis("Vertical") * springForce * speed;
            this.Fy = wheelVelocityLS.x * springForce;

            this.trb.AddForceAtPosition(suspensionForce + (Fx * transform.forward.ToTSVector()) + (Fy * (transform.right.ToTSVector() * -1)), hit.point);
        }
    }