public void ReleasePokemonBall()
    {
        Vector3 targetPos  = transform.position + (transform.forward * 5.0f);
        Vector3 throwSpeed = PhysicsCalculations.CalculateBestThrowSpeed(pokemonBall.transform.position, targetPos, 1.0f);

        pokemonBall.transform.parent = null;
        pokemonBallRBody.AddForce(throwSpeed, ForceMode.Impulse);
        pokemonBallRBody.useGravity = true;
    }
コード例 #2
0
    private static float GetRotationSpeed(double blackHoleMass, float distance)
    {
        // 0.01, 2.5
        // 0.009, 1.0

        double newDistance = 0.009 + ((distance - 0.01) * (1.0 - 0.009)) / (2.5 - 0.01);

        double timeDilation = PhysicsCalculations.getTimeDilationAmount(1.0, blackHoleMass, newDistance);

        float rotationSpeed = (1.0f - (float)timeDilation) + 0.2f;

        return(rotationSpeed);
    }
コード例 #3
0
    void FixedUpdate()
    {
        if (target)
        {
            xDeg += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
            yDeg -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;

            xDeg = PhysicsCalculations.ClampAngle(xDeg, curXMin, curXMax);
            yDeg = PhysicsCalculations.ClampAngle(yDeg, curYMin, curYMax);

            // Set camera rotation
            Quaternion rotation = Quaternion.Euler(yDeg, xDeg, 0.0f);

            // Calculate the desired distance
            desiredDistance  -= Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * zoomRate * Mathf.Abs(desiredDistance);
            desiredDistance   = Mathf.Clamp(desiredDistance, minDistance, maxDistance);
            correctedDistance = desiredDistance;

            // Calculate desired camera position
            Vector3 position = target.position - (rotation * Vector3.forward * desiredDistance);

            // Check for collision using the true target's desired registration point as set by user using height
            RaycastHit collisionHit;
            Vector3    trueTargetPosition = new Vector3(target.position.x, target.position.y, target.position.z);

            // If there was a collision, correct the camera position and calculate the corrected distance
            bool isCorrected = false;
            if (Physics.Linecast(trueTargetPosition, position, out collisionHit, collisionLayers))
            {
                // Calculate the distance from the original estimated position to the collision location,
                // subtracting out a safety "offset" distance from the object we hit.  The offset will help
                // keep the camera from being right on top of the surface we hit, which usually shows up as
                // the surface geometry getting partially clipped by the camera's front clipping plane.
                correctedDistance = Vector3.Distance(trueTargetPosition, collisionHit.point) - offsetFromWall;
                isCorrected       = true;
            }

            // For smoothing, lerp distance only if either distance wasn't corrected, or correctedDistance is more than currentDistance
            currentDistance = !isCorrected || correctedDistance > currentDistance?Mathf.Lerp(currentDistance, correctedDistance, Time.deltaTime *zoomDampening) : correctedDistance;

            // Keep within limits
            currentDistance = Mathf.Clamp(currentDistance, minDistance, maxDistance);

            // Recalculate position based on the new currentDistance
            position = target.position - (rotation * Vector3.forward * currentDistance);

            //Finally Set rotation and position of camera
            transform.rotation = rotation;
            transform.position = position;
        }
    }
コード例 #4
0
    private void Update()
    {
        radius = PhysicsCalculations.CalculateSchwarzschildToFloat(Mass);

        // Escape velocity never changes with the black hole radius,
        // Since it will always be the speed of light.
        escapeVelocity = PhysicsCalculations.CaclulateEscapeVelocityToFloat(Mass, radius);

        transform.localScale = new Vector3(radius, radius, radius);

        // Get the latest data values from the object, and display them
        // To the provided info text box.
        ExtractDisplayableDataValues();
        UpdateInfoWindow();
    }
コード例 #5
0
    void Update()
    {
        if (isBlackHole)
        {
            float distance    = Vector3.Distance(blackHole.transform.position, properTimeFrame.transform.position);
            float newDistance = 0.005f + (distance - 0) * (0.1f - 0.005f) / (20f - 0);

            float timeDilation = 1.0f - (float)PhysicsCalculations.getTimeDilationAmount(1.0, orbitObject.mass, distance);

            //Debug.Log(timeDilation);
        }
        //    transform.position = new Vector3(Mathf.PingPong(Time.time * timeDilation, 0.5f), transform.position.y, transform.position.z);
        //} else
        //{
        //    transform.position = new Vector3(Mathf.PingPong(Time.time, 1), transform.position.y, transform.position.z);
        //}
    }
コード例 #6
0
    private void FixedUpdate()
    {
        GameObject orbitTarget;

        for (int i = 0; i < orbitTargets.Count; i++)
        {
            orbitTarget = orbitTargets[i];
            Vector3 gravDir   = orbitTarget.transform.position - gameObject.transform.position;
            double  mag       = (double)gravDir.magnitude;
            double  gravForce = PhysicsCalculations.getGravitationalForceBasic(orbitTarget.GetComponent <OrbitObjectScript>().mass, mag * scaleManager.distanceScale / 1000);

            gravDir.Normalize();
            //gravForce = PhysicsCalculations.getAccelerationFromForce(mass, gravForce);

            float gravForce_f = PhysicsCalculations.ConvertDoubleToFloat(gravForce / scaleManager.velocityScale) * Time.smoothDeltaTime;
            gravDir.Scale(new Vector3(gravForce_f, gravForce_f, gravForce_f));
            rb.velocity += gravDir;
        }
        initialVelocty = rb.velocity;
    }
 void FALLUpdate()
 {
     if (trainerControl)
     {
         if (PhysicsCalculations.IsGrounded(trainer.components.collider, 0.1f, trainer.colliderRadius))
         {
             currentState = States.IDLE;
             return;
         }
     }
     else
     {
         if (PhysicsCalculations.IsGrounded(pokemon.components.collider, 0.1f, pokemon.colliderRadius))
         {
             pokemon.components.anim.Land();
             currentState = States.IDLE;
             return;
         }
     }
 }
 void IDLEUpdate()
 {
     if (trainerControl)
     {
         if (trainer.components.input.curInput.jump)
         {
             currentState = States.PRE_JUMP;
             return;
         }
         if (!PhysicsCalculations.IsGrounded(trainer.components.collider, 0.1f, trainer.colliderRadius))
         {
             currentState = States.FALL;
             return;
         }
         if (trainer.components.input.curInput.movement != Vector3.zero)
         {
             currentState = trainer.components.input.curInput.walk ? States.WALK : States.RUN;
             return;
         }
     }
     else
     {
         if (pokemon.components.input.curInput.jump && canMove)
         {
             currentState = States.PRE_JUMP;
             return;
         }
         if (!PhysicsCalculations.IsGrounded(pokemon.components.collider, 0.1f, pokemon.colliderRadius))
         {
             currentState = States.FALL;
             return;
         }
         if (pokemon.components.input.curInput.movement != Vector3.zero && canMove)
         {
             currentState = pokemon.components.input.curInput.walk ? States.WALK : States.RUN;
             return;
         }
     }
 }
    void FixedUpdate()
    {
        if (trainerControl)
        {
            if (lookDirection != Vector3.zero)
            {
                trainer.components.rigidbody.rotation = Quaternion.LookRotation(lookDirection);
            }

            velocityChange   = targetVelocity - trainer.components.rigidbody.velocity;
            velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
            velocityChange.y = 0.0f;
            velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
            trainer.components.rigidbody.AddForce(velocityChange, ForceMode.VelocityChange);

            if (!PhysicsCalculations.IsGrounded(trainer.components.collider, 0.1f, trainer.colliderRadius))
            {
                trainer.components.rigidbody.AddForce(new Vector3(0.0f, -trainer.gravity * trainer.components.rigidbody.mass, 0.0f));
            }
        }
        else
        {
            if (lookDirection != Vector3.zero)
            {
                pokemon.components.rigidbody.rotation = Quaternion.LookRotation(lookDirection);
            }

            velocityChange   = targetVelocity - pokemon.components.rigidbody.velocity;
            velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
            velocityChange.y = 0.0f;
            velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
            pokemon.components.rigidbody.AddForce(velocityChange, ForceMode.VelocityChange);

            if (!PhysicsCalculations.IsGrounded(pokemon.components.collider, 0.1f, pokemon.colliderRadius))
            {
                pokemon.components.rigidbody.AddForce(new Vector3(0.0f, -pokemon.gravity * pokemon.components.rigidbody.mass, 0.0f));
            }
        }
    }
 void JUMPEnterState()
 {
     if (trainerControl)
     {
         trainer.components.rigidbody.velocity = new Vector3(trainer.components.rigidbody.velocity.x, PhysicsCalculations.CalculateJumpSpeed(trainer.jumpHeight, trainer.gravity),
                                                             trainer.components.rigidbody.velocity.z);
     }
     else
     {
         pokemon.components.rigidbody.velocity = new Vector3(pokemon.components.rigidbody.velocity.x, PhysicsCalculations.CalculateJumpSpeed(pokemon.CurJumpHeight, pokemon.gravity),
                                                             pokemon.components.rigidbody.velocity.z);
     }
 }
 void RUNUpdate()
 {
     if (trainerControl)
     {
         if (trainer.components.input.curInput.walk)
         {
             currentState = States.WALK;
             return;
         }
         if (trainer.components.input.curInput.jump)
         {
             currentState = States.PRE_JUMP;
             return;
         }
         if (!PhysicsCalculations.IsGrounded(trainer.components.collider, 0.1f, trainer.colliderRadius))
         {
             currentState = States.FALL;
             return;
         }
         if (trainer.components.input.curInput.movement != Vector3.zero)
         {
             targetVelocity = trainer.components.input.curInput.movement * trainer.walkSpeed * trainer.runMultiplier;
         }
         else
         {
             currentState = States.IDLE;
             return;
         }
     }
     else
     {
         if (!canMove)
         {
             currentState = States.IDLE;
             return;
         }
         if (pokemon.components.input.curInput.walk)
         {
             currentState = States.WALK;
             return;
         }
         if (pokemon.components.input.curInput.jump)
         {
             currentState = States.PRE_JUMP;
             return;
         }
         if (!PhysicsCalculations.IsGrounded(pokemon.components.collider, 0.1f, pokemon.colliderRadius))
         {
             currentState = States.FALL;
             return;
         }
         if (pokemon.components.input.curInput.movement != Vector3.zero)
         {
             targetVelocity = pokemon.components.input.curInput.movement * pokemon.CurWalkSpeed * pokemon.runMultiplier;
         }
         else
         {
             currentState = States.IDLE;
             return;
         }
     }
 }