예제 #1
0
 /**
  * Update the velocity with gravity and clamp speed max
  * Used by PlayerPath to simulate the path
  */
 public Vector3 UpdateVelocity(Vector3 vel, Vector3 pos, GravityBody[] obstacles, float dt)
 {
     if (!ignoreGravity)
     {
         vel += gravity.GetGravity(obstacles, pos) * dt;             // add gravity
     }
     if (vel.magnitude > speedCap)
     {
         vel = vel.normalized * speedCap;             // clamp
     }
     return(vel);
 }
예제 #2
0
 void Start()
 {
     gravity = new Gravity (Application.dataPath+"/Resources/Dg01_cnt2.5x2.bytes");
     Input.location.Start();           //enable location settings
     Input.compass.enabled = true;
     locationStatus = LocationServiceStatus.Running;
     lon = 0; alt = 0; lat = 0;
     dlon = 0; dalt = 0; dlat = 0;
     gAn=gravity.GetGravity(lat,lon,alt);
     gAcc = gravity.GetAcceleration (gAn);
     startLocationService();               //begin GPS transmittion
 }
예제 #3
0
    private void FixedUpdate()
    {
        float dt = Time.deltaTime;

        gravity = gravityManager.GetGravity(rb.position, gravityMax);

        Debug.Log(gravity);

        if (!isGravity)
        {
            gravity = Vector3.zero;
        }

        rb.rotation *= Quaternion.AngleAxis(rotateIntensity * rotateSpeed * dt, Vector3.up);

        thrust         += thrustIntensity * thrustPower * dt;
        thrust          = Mathf.Max(thrust, thrustMin);
        thrust          = Mathf.Min(thrust, thrustMax);
        thrushtVelocity = player.forward * thrust * thrustPower * dt;

        velocity  = velocity == Vector3.zero ? player.forward * thrustMin * dt : velocity;
        velocity += gravity * dt;
        velocity += thrushtVelocity * dt;

        velocity = Vector3.ClampMagnitude(velocity, speedMax);

        if (isDebug)
        {
            Debug.DrawLine(rb.position, rb.position + thrushtVelocity * 5, Color.red);             // thrust
            Debug.DrawLine(rb.position, rb.position + velocity.normalized * 5, Color.green);       // path
        }

        rb.position += velocity * dt;

        DrawPath(dt);
    }
예제 #4
0
    void FixedUpdate()
    {
        Vector3 g = Gravity.GetGravity(transform.position);

        body.AddForce(g * 110 * Time.fixedDeltaTime);
    }