예제 #1
0
 void FixedUpdate()
 {
     if (!dontAffectForce)
     {
         planet.Attract(transform);
     }
     else
     {
         planet.Attract(transform);
     }
 }
예제 #2
0
 void FixedUpdate()
 {
     if (customForce)
     {
         planet.Attract(transform, customGravity, false, false);
     }
     else if (!dontAffectForce)
     {
         planet.Attract(transform);
     }
     else
     {
         planet.Attract(transform, 0, true, true);
     }
 }
예제 #3
0
    void Update()
    {
        if (usePhysicsGravity)
        {
            return;
        }
        ;

        planet.Attract(transform, adjustment);

        if (!adjusted)
        {
            float      bodyHeight = GetComponent <Collider>().bounds.size.y;
            float      halfHeight = bodyHeight / 2;
            RaycastHit hit;
            Vector3    origin = transform.position;
            if (Physics.Raycast(origin, -transform.up.normalized, out hit, Mathf.Infinity, planetLayer))
            {
                float distanceToAdjust = Vector3.Distance(origin - (transform.up.normalized * halfHeight), hit.point);
                if (distanceToAdjust > adjustmentMin && distanceToAdjust < adjustmentMax)
                {
                    adjustment = distanceToAdjust;
                    Adjust(adjustment);
                    Debug.Log("adjusting " + transform.name + " by " + adjustment);
                }
            }
        }
    }
예제 #4
0
 void FixedUpdate()
 {
     if (attractor)
     {
         attractor.Attract(myTransform, gravityMutiple);
     }
 }
예제 #5
0
 void FixedUpdate()
 {
     if (!isPlayer || (isPlayer && !GetComponent <PlayerMovement>().LevelOver))
     {
         bool pissOff   = false; //i hate every bit of this fixed updates. Why did I have to have this many if statements just so the enemies and player can have the same script for physics.
         bool doAttract = true;
         if (isPlayer)
         {
             if (!GetComponent <PlayerMovement>().flying)
             {
                 pissOff = true;
                 if (attractor && !(attractor.planetType != GravityAttractor.planetTypes.rectangle || (isPlayer && attractor.planetType == GravityAttractor.planetTypes.rectangle && !GetComponent <PlayerMovement>().IsGrounded())))
                 {
                     doAttract = false;
                 }
             }
         }
         else
         {
             pissOff = true;
         }
         if (pissOff)
         {
             if (attractor)
             {
                 attractor.Attract(myTransform);
             }
             if (doAttract)
             {
                 rigidbody.AddForce(-transform.up * 250); //player gravity without the actual gravity. I don't know its weird
             }
         }
     }
 }
 private void FixedUpdate()
 {
     if (attractor)
     {
         attractor.Attract(rigidBody);
     }
 }
예제 #7
0
    //FixedUpdate gets called at a regular interval independent from the framerate
    void FixedUpdate()
    {
        if (planetGravity)
        {
            targetGravity = targetPlanet.GetComponent <GravityAttractor> ();
            targetGravity.Attract(transform);
        }
        else
        {
            // Apply downwards gravity to body
            transform.GetComponent <Rigidbody> ().AddForce(gravityUp * gravity);
            // Allign bodies up axis with the centre of planet
            Quaternion targetRotation = Quaternion.FromToRotation(transform.up, gravityUp) * transform.rotation;
            float      angularSpeed   = 3.0f;
            if (transform.rotation != targetRotation)
            {
                //transform.rotation = Quaternion.Lerp (transform.rotation, targetRotation, angularSpeed);

                transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, angularSpeed);
                //print("Player: " + transform.rotation + ", target: " + targetRotation);
                //transform.Rotate(0, yAmount, 0, Space.Self);
            }
        }
        //linear interpolation
        //Zielposition über Zeitraum
    }
예제 #8
0
 void FixedUpdate()
 {
     if (planet && !beingControlled)
     {
         planet.Attract(thisRigidBody, gravityMultiplier);
     }
 }
예제 #9
0
 void FixedUpdate()
 {
     if (attractor)
     {
         attractor.Attract(this);
     }
 }
예제 #10
0
 private void FixedUpdate()
 {
     if (!settings.isPaused)
     {
         planet.Attract(this);
     }
 }
예제 #11
0
 void FixedUpdate()
 {
     if (attractor)
     {
         attractor.Attract(myTransform);
     }
 }
예제 #12
0
    void FixedUpdate()
    {
        // Allow this body to be influenced by planet's gravity
        if (rigidbody.gameObject.tag == "Player")
        {
            if (rigidbody.gameObject.GetComponent <Stats>().buffs[(int)buff.Gravityless] == 0) //if you don't have the gravityless buff, gravity applies
            {
                planet.Attract(rigidbody);
            }
        }

        else
        {
            planet.Attract(rigidbody); //all non players will face gravity
        }
    }
 private void FixedUpdate()
 {
     GetComponent <Rigidbody>().MovePosition(GetComponent <Rigidbody>().position + transform.TransformDirection(moveDir) * moveSpeed * Time.deltaTime);
     if (_GravityAtrtractor)
     {
         _GravityAtrtractor.Attract(myTransform);
     }
 }
예제 #14
0
 void FixedUpdate()
 {
     GetComponent <Rigidbody>().MovePosition(GetComponent <Rigidbody>().position + transform.TransformDirection(direction) * speed * Time.deltaTime);
     if (_FauxGravityAttractor)
     {
         _FauxGravityAttractor.Attract(myTransform);
     }
 }
예제 #15
0
 void FixedUpdate()
 {
     // Allow this body to be influenced by planet's gravity
     if (rigidbody != null && planet != null)
     {
         planet.Attract(rigidbody);
     }
 }
예제 #16
0
    void FixedUpdate()
    {
        ImpactMovementRoutine();
        switch (m_State)
        {
        case "Default":
            m_CenterSphere.Attract(m_Rigidbody, m_Transform, 1.0f);
            VerticalInputHandler();
            HorizontalInputHandler();
            m_PlayerMesh.transform.position = m_Transform.position;
            m_PlayerMesh.transform.rotation = m_Transform.rotation;
            m_PlayerMesh.transform.Rotate(m_PlayerMesh.transform.forward, 180.0f, Space.World);
            m_PlayerMesh.transform.Rotate(m_PlayerMesh.transform.forward, m_TurnAngle, Space.World);
            break;

        case "Spinning":
            m_CenterSphere.Attract(m_Rigidbody, m_Transform, 1.0f);
            VerticalInputHandler();
            HorizontalInputHandler();
            m_PlayerMesh.transform.position = m_Transform.position;
            m_PlayerMesh.transform.rotation = m_Transform.rotation;
            m_PlayerMesh.transform.Rotate(m_PlayerMesh.transform.forward, 180.0f, Space.World);
            SpinningRoutine();
            break;

        case "Loop":
            LoopRoutine();
            m_PlayerMesh.transform.position = m_Transform.position;
            m_PlayerMesh.transform.rotation = m_Transform.rotation;
            m_PlayerMesh.transform.Rotate(m_PlayerMesh.transform.forward, 180.0f, Space.World);
            break;

        case "Damaged":
            m_CenterSphere.Attract(m_Rigidbody, m_Transform, 1.0f);
            m_PlayerMesh.transform.position = m_Transform.position;
            m_PlayerMesh.transform.rotation = m_Transform.rotation;
            m_PlayerMesh.transform.Rotate(m_PlayerMesh.transform.forward, 180.0f, Space.World);
            DamagedRoutine();
            break;

        default:
            break;
        }
        RadarArrowRoutine();
    }
예제 #17
0
 void FixedUpdate()
 {
     // Allow this body to be influenced by planet's gravity
     if (planet == null)
     {
         Debug.Log("Planet is null");
     }
     planet.Attract(this.rb);
 }
예제 #18
0
 void FixedUpdate()
 {
     // Allow this body to be influenced by planet's gravity
     planet.Attract(rigidbody);
     if (fpc.grounded == true)
     {
         planet.React(rigidbody);
     }
 }
예제 #19
0
 void FixedUpdate()
 {
     if (placeOnSurface)
     {
         attractor.PlaceOnSurface(rb);
     }
     else
     {
         attractor.Attract(rb);
     }
 }
예제 #20
0
 void FixedUpdate()
 {
     if (attractor)
     {
         attractor.Attract(myTransform);
     }
     else if (orbit)
     {
         orbit.Attract(myTransform);
     }
 }
예제 #21
0
    void FixedUpdate()
    {
        if (attract == null)
        {
            Physics.gravity = -Vector3.up * 9.8f;
            return;
        }

        //플레이어의 중력 및 회전계산 후 적용
        attract.Attract(rigid);
    }
예제 #22
0
    void FixedUpdate()
    {
        //Debug.Log(transform.position + " " + planet_.transform.position);

        Debug.Log(controller_script_.is_on_spring_);
        if (!controller_script_.is_on_spring_)
        {
            planet_script_.Attract(transform);
            rigidbody_.freezeRotation = true;
        }
        else
        {
            rigidbody_.useGravity = true;
        }
    }
예제 #23
0
파일: Unit.cs 프로젝트: bmjoy/ecowars
    //Rotate, move unit towards destination, affect gravity and animate
    public void Move(Vector3 destination)
    {
        //only rotate normal to the planet
        Vector3    projectedDestination = Vector3.ProjectOnPlane(destination, transform.up);
        Quaternion targetRotation       = Quaternion.LookRotation(projectedDestination, Vector3.up);

        transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, Time.fixedDeltaTime * rotationSpeed);

        //move forward in the local axis
        rb.MovePosition(rb.position + transform.forward * Time.fixedDeltaTime * speed);

        //affect gravity
        planet.Attract(transform);

        //animate movement
        AnimateWalk();
    }
예제 #24
0
    public virtual void attract(bool applyForce)
    {
        //transform.parent = null;
        int closePlanets = 0;

        minimumPlanetDistance = float.MaxValue;
        foreach (GameObject planet in planets)
        {
            GravityAttractor gravityAttractor = planet.GetComponent <GravityAttractor> ();
            float            distance         = 0f;
            if (gravityAttractor.Attract(transform, out distance, applyForce, hasToChangeFacing, gravityMultiplyier))
            {
                closePlanets++;
            }
            if (distance < minimumPlanetDistance)
            {
                minimumPlanetDistance = distance;
            }
        }
    }
예제 #25
0
 void FixedUpdate()
 {
     // Allow this body to be influenced by planet's gravity
     if (planet != null && canAttract == true && planet.name == transform.name + " Hook")
     {
         if (lowGravity == true)
         {
             rigidbody.useGravity = false;
         }
         else
         {
             rigidbody.useGravity = true;
         }
         planet.Attract(rigidbody);
     }
     if (canAttract == false)
     {
         rigidbody.useGravity = true;
     }
 }
예제 #26
0
    void Move()
    {
        Speed = _velocity.magnitude;

        _moveVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
        _moveVector = FPCam.transform.localToWorldMatrix.MultiplyVector(_moveVector).normalized;

        body.AddForce(_moveVector * _movementModifier * MoveAcceleration * Time.deltaTime, ForceMode.VelocityChange);

        _moveVector = new Vector3(0, Input.GetAxis("Jump"), 0);

        body.AddForce(_moveVector * 1.6f * _movementModifier * MoveAcceleration * Time.deltaTime, ForceMode.VelocityChange);

        _moveVector = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Jump"), Input.GetAxis("Vertical"));

        if (!ToggleRun)
        {
            _movementModifier = (Input.GetButton("Run") ? RunModifier : 1);
        }

        if (body.velocity.magnitude > 0)
        {
            if (body.velocity.magnitude < Deceleration * Time.deltaTime)
            {
                body.AddForce(-body.velocity, ForceMode.VelocityChange);
            }
            else
            {
                _velocity = -body.velocity;
                _velocity.Normalize();
                body.AddForce(_velocity * Deceleration * Time.deltaTime, ForceMode.VelocityChange);
                _velocity = body.velocity;
            }
        }

        if (body.velocity.magnitude > MaxSpeed && _movementModifier == 1 && !_runRecent)
        {
            body.AddForce(-body.velocity, ForceMode.VelocityChange);
            _velocity.Normalize();
            _velocity *= MaxSpeed;
            body.AddForce(_velocity, ForceMode.VelocityChange);
            _velocity = body.velocity;
        }
        else if (body.velocity.magnitude > MaxSpeed * _movementModifier && _movementModifier > 1)
        {
            _runRecent = true;
            _runDown++;
            if (_movementModifier > 1)
            {
                _runDown = 0;
            }
            body.AddForce(-body.velocity, ForceMode.VelocityChange);
            _velocity.Normalize();
            _velocity *= MaxSpeed * (_movementModifier - (_runDown * Time.deltaTime));
            body.AddForce(_velocity, ForceMode.VelocityChange);
            _velocity = body.velocity;
        }
        else if (body.velocity.magnitude > MaxSpeed)
        {
            _runRecent = true;
            if (_movementModifier == 1)
            {
                body.AddForce(-_moveVector * MoveAcceleration * Time.deltaTime, ForceMode.VelocityChange);
            }
            _runDown++;
            if (_movementModifier > 1)
            {
                _runDown = 0;
            }
        }
        else if (_runRecent)
        {
            _runRecent = false;
            _runDown   = 0;
        }

        if (State == CharacterState.Grounded && !_onPlanet)
        {
            planet.Attract(body, false);
        }
    }
예제 #27
0
 void FixedUpdate()
 {
     // Allow this body to be influenced by planet's gravity
     planet.Attract(rb);
 }
예제 #28
0
 void FixedUpdate()
 {
     // Allow this body to be influenced by sea's gravity
     sea.Attract(rigidBody);
 }
예제 #29
0
 void FixedUpdate()
 {
     // Allow this body to be influenced by planet's gravity
     planet.Attract(rigBody, UpToNormal);
 }
예제 #30
0
 void FixedUpdate()
 {
     planet.Attract(rigidbody);
 }