public void Spawn(GameObject goal, Transform parent)
 {
     this.goal = goal;
     indicator = Instantiate(indicatorPrefab, parent);
     indicator.SetActive(false);
     physics = CustomPhysics.Instance;
 }
 /// <summary>
 /// Removes a physics object to the manager list of objects.
 /// </summary>
 /// <returns></returns>
 public void RemovePhysicsObjectToList(CustomPhysics physicsObject)
 {
     if (physicsObjectsInWorld.Contains(physicsObject) == true)
     {
         physicsObjectsInWorld.Remove(physicsObject);
     }
 }
    //List<int> leftPos = new List<int>();
    //List<int> rightPos = new List<int>();
    //float buildingFallVelocity = 10;

    //// to allow use of coroutines in non-monobehavior scripts
    //public void StartShootTimer()
    //{
    //	StartCoroutine("ShootTimer");
    //}

    //IEnumerator ShootTimer()
    //{
    //	if(!player.canShoot)
    //	{
    //		yield return new WaitForSeconds(0.15f);
    //		player.canShoot = true;
    //	}
    //}

    void Start()
    {
        Application.targetFrameRate = -1;

        physics    = new CustomPhysics();       // initialize the physics
        rayCast    = new CustomRayCast();
        rayCast.pD = this;
        //explode = new Explode ();
        explode.pD = this;
        //player = new Player (-100, 500); // create the player
        //ourPlayerAnimation.X = player.x;
        //ourPlayerAnimation.Y = player.y;
        //ourPlayerAnimation.Enabled = true;
        //player.pD = this;
        //player.physics = physics;
        //physics.Add (player); // Add player to physics
        //player.targetCamera = Camera.main.GetComponent<CameraFollow>();
        //controls.player = player;

        //controls = new Controls(this, physics);

        //int minX = this.World.Minimum.x;
        //int maxX = this.World.Maximum.x;
        //for (int y = this.World.Minimum.y; y < this.World.Maximum.y; y++)
        //{
        //    leftPos.Add(minX);
        //    rightPos.Add(maxX);
        //}
        intializeCities();
    }
Beispiel #4
0
    private void Update()
    {
        if (SimulationHalted)
        {
            return;
        }
        if (UnderSimulation == false && IsDragable == true)
        {
            if (dragging == true)
            {
                Vector3 dpos = Camera.main.ScreenToWorldPoint(Input.mousePosition) - prevMousePosition;
                this.transform.position += new Vector3(dpos.x, dpos.y);
                prevMousePosition        = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            }

            if (Input.GetMouseButtonDown(0) == true)
            {
                Vector2 mouseWorldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

                if (CustomPhysics.InsidePolygon(this.ToPointArray(), mouseWorldPosition))
                {
                    dragging          = true;
                    prevMousePosition = mouseWorldPosition;
                }
            }
            if (Input.GetMouseButtonUp(0) == true)
            {
                dragging = false;
            }
        }
    }
Beispiel #5
0
    Vector3 acceleration(ProjectileODEData state, float time)
    {
        Vector3 airVelocity = CustomPhysics.AirVelocity(state.Velocity);
        Vector3 drag        = 0.5f * (-airVelocity.normalized * airVelocity.sqrMagnitude) *
                              CustomPhysics.AirDensity * state.Area * state.DragCoefficient / state.Mass;

        return(CustomPhysics.Gravity + drag);
    }
Beispiel #6
0
 void Start()
 {
     physicsScript = GetComponent <CustomPhysics>();
     physicsScript.ResolveCollisions(gameObject);
     //rb = GetComponent<Rigidbody>();
     //rb.freezeRotation = true;
     //mainCamera = transform.GetChild(0).gameObject;
     //GetComponent<MeshRenderer>().enabled = false;
 }
Beispiel #7
0
 void Start()
 {
     _lockTransform = deathCanvas.transform.rotation;
     _pVar          = GetComponent <PlayerVariables>();
     _phy           = GetComponent <CustomPhysics>();
     _normalState   = new NormalState(_pVar);
     _boostState    = new BoostState(_pVar);
     _currentState  = _normalState;
     _image         = deathCanvas.GetComponentInChildren <Image>();
 }
Beispiel #8
0
    // Use this for initialization
    public virtual void Start()
    {
        animator = GetComponentInChildren <Animator>();
        physics  = GetComponent <CustomPhysics>();
        player   = GetComponent <PlayerController>();

        rend = GetComponentInChildren <SpriteRenderer>();

        spriteSheet = Resources.LoadAll <Sprite>(spriteSheetPath);
        whiteSheet  = Resources.LoadAll <Sprite>(whiteSheetPath);
    }
Beispiel #9
0
 private void Start()
 {
     _manager = FindObjectOfType <BattleController>();
     _manager.AddPlayer(gameObject);
     _phy            = gameObject.GetComponent <CustomPhysics>();
     _col            = gameObject.GetComponent <SphereCollider>();
     _normalState    = new NormalState(_speed, _maxVel, _rotateSpeed, _mesh);
     _boostingState  = new BoostingState(_boostTime, _boostMaxSpeed, _mesh);
     _runPUState     = new RunPowerUpState(_runPUTime, _speed * _runPUSpeedMultiplier, _rotateSpeed, _mesh);
     _currentState   = _normalState;
     _currentPowerUp = new NoPowerUp();
 }
Beispiel #10
0
 public override void OnCustomCollisionStay(CustomCollision collision)
 {
     if (collision.gameObject.CompareTag("Player"))
     {
         CustomPhysics _playerBody = collision.gameObject.GetComponent <CustomPhysics>();
         if (_isX)
         {
             // FIXME : Find a better way to have the player move on conveyors
             // Currently inputs are not taken into account for some reason.
             _playerBody.Velocity = _playerBody.Velocity + Vector2.right * _speed;
         }
         else
         {
             _playerBody.Velocity = _playerBody.Velocity + Vector2.up * _speed;
         }
     }
 }
Beispiel #11
0
    private void Awake()
    {
        //Finds a collision manager in the world. If found, adds this collider to the manager list.
        colliderManager = FindObjectOfType <ColliderManager>();
        if (colliderManager == null)
        {
            Debug.LogError("You need to have a collision manager in the scene!");
        }
        else
        {
            colliderManager.AddColliderToList(this);
        }

        //Finds a Custom Physics component on this object.
        physics = GetComponent <CustomPhysics>();

        //Sets the transform and scale of the collider the same size as the object.
        position = transform.localPosition;
        scale    = transform.localScale;
    }
Beispiel #12
0
 // Use this for initialization
 protected virtual void Start()
 {
     physics = GetComponent <CustomPhysics>();
     box     = GetComponent <BoxCollider2D>();
 }
 /// <summary>
 /// Adds a physics object to the manager list of objects.
 /// </summary>
 /// <returns></returns>
 public void AddPhysicsObjectToList(CustomPhysics physicsObject)
 {
     physicsObjectsInWorld.Add(physicsObject);
 }
Beispiel #14
0
 public void Start()
 {
     physics = pD.physics;
     rayCast = pD.rayCast;
     //explode = dT.explode;
 }
Beispiel #15
0
 // Use this for initialization
 public virtual void Start()
 {
     animator = GetComponentInChildren <Animator>();
     physics  = GetComponent <CustomPhysics>();
     player   = GetComponent <PlayerController>();
 }
Beispiel #16
0
 /// <summary>
 /// Fire a bullet forward form the canon.
 /// </summary>
 /// <returns></returns>
 private void FireBullet(float fireForce)
 {
     bullet = Instantiate(physicsObjectToFirePrefab, transform.position, Quaternion.identity);
     bullet.ApplyImpulse(canonPipe.transform.up * fireForce);
 }
Beispiel #17
0
 // Use this for initialization
 protected override void Start()
 {
     base.Start();
     physics = GetComponent <CustomPhysics>();
     sprite  = GetComponent <SpriteRenderer>();
 }
Beispiel #18
0
 protected virtual void Start()
 {
     m_customPhysics = GetComponent <CustomPhysics>();
 }
Beispiel #19
0
 void Start()
 {
     animator = GetComponentInChildren <Animator>();
     physics  = GetComponent <CustomPhysics>();
     box      = GetComponent <BoxCollider2D>();
 }
Beispiel #20
0
    private void Update()
    {
        if (Input.GetMouseButtonDown(0) == true)
        {
            Vector2        pos  = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            RaycastHit2D[] hits = Physics2D.RaycastAll(pos, Vector2.zero, float.PositiveInfinity);

            if (simArray[0].UnderSimulation == true)
            {
                return;
            }

            if (hits.ToList().Exists(_ => _.collider.gameObject == this.gameObject))
            {
                float eps1 = 0.001f;
                float eps2 = 0.03f;

                bool isValid = true;

                foreach (RigidBodySimulation lhs in simArray)
                {
                    foreach (RigidBodySimulation rhs in simArray)
                    {
                        float   depth;
                        Vector2 deepestPoint, direction;
                        if (lhs != rhs)
                        {
                            CustomPhysics.GetPenetrationDepth(lhs.ToPointArray(), rhs.ToPointArray(), out depth, out deepestPoint, out direction);
                            if (Mathf.Abs(depth) > eps1)
                            {
                                Debug.Log("failed at " + lhs.name + ", " + rhs.name);
                                isValid = false;
                                goto there;
                            }
                        }
                    }
                }

                foreach (RigidBodySimulation sim in simArray)
                {
                    if (sim.LinearVelocity.magnitude > eps2 || Mathf.Abs(sim.AngularVelocity) > eps2)
                    {
                        Debug.Log("failed at " + sim.name);
                        Debug.Log("linvel " + sim.LinearVelocity.magnitude.ToString() + ", angvel " + sim.AngularVelocity.ToString());
                        isValid = false;
                        goto there;
                    }
                }
there:
                if (isValid == true)
                {
                    foreach (RigidBodySimulation sim in simArray)
                    {
                        sim.StartSimulation();
                    }
                }
                else
                {
                    overlapWarn.StartWarn();
                }
            }
        }
    }
Beispiel #21
0
 public Controls(PixelDestruction pD, CustomPhysics pS)
 {
     this.pD      = pD;
     this.physics = pS;
 }
Beispiel #22
0
 void Start()
 {
     instance = this;
 }
Beispiel #23
0
    void FixedUpdate()
    {
        if (SimulationHalted)
        {
            return;
        }
        if (!UnderSimulation && dragging)
        {
            return;
        }
        if (!UnderSimulation && !IsDragable)
        {
            return;
        }
        //if (underSimulation == false)
        //    return;

        float dt = Time.fixedDeltaTime;

        Vector2 worldForce  = Vector2.zero;
        float   worldTorque = 0;

        //gravity
        Vector2 gravity = mass * gravityVector;

        worldForce += gravity;

        //penalty method

        float degreeAngle = transform.rotation.eulerAngles.z;

        RigidBodySimulation[] simArray = GameObject.FindObjectsOfType <RigidBodySimulation>();
        // Make some overlapboxall

        bool collided = false;

        foreach (RigidBodySimulation sim in simArray)
        {
            if (sim == this)
            {
                continue;
            }
            if (this.IsEndDomino == false && sim.gameObject.GetComponent <TargetCube>() != null)
            {
                continue;
            }


            float   depth;
            Vector2 deepestPoint;
            Vector2 direction;

            CustomPhysics.GetPenetrationDepth(
                this.ToPointArray(), sim.ToPointArray(),
                out depth, out deepestPoint, out direction);
            if (depth != 0)
            {
                if (!UnderSimulation)
                {
                    if (sim.dragging)
                    {
                        return;
                    }
                    LinearVelocity      = Vector2.zero;
                    AngularVelocity     = 0;
                    sim.LinearVelocity  = Vector2.zero;
                    sim.AngularVelocity = 0;

                    transform.Translate(transform.InverseTransformDirection((depth) * direction));
                    return;
                }
                else
                {
                    if (tc != null && sim.IsEndDomino == true)
                    {
                        tc.Collided();
                    }

                    Vector2 f = penaltyConstant * direction * depth;
                    worldForce += f;

                    Vector2 r = deepestPoint - (Vector2)transform.position;
                    if (Mathf.Abs(worldTorque) > 0.01 || Mathf.Abs(r.x * f.y - r.y * f.x) > 0.01)
                    {
                        worldTorque += r.x * f.y - r.y * f.x;
                    }

                    collided = true;

                    float   dotproduct            = Vector2.Dot(LinearVelocity, direction);
                    Vector2 directionwiseVelocity = dotproduct * direction;

                    LinearVelocity =
                        (LinearVelocity - directionwiseVelocity) * (1 - linearDampingCoeffX * dt) //perpendicular to normal
                        + directionwiseVelocity * (1 - linearDampingCoeffY * dt);                 //normal
                }
                //CustomPhysics.DebugVector2(deepestPoint);
            }
        }


        if (collided == true)
        {
            AngularVelocity *= (1 - angularDampingCoeff * dt);
        }

        LinearVelocity += dt * AngularVelocity * new Vector2(LinearVelocity.y, -LinearVelocity.x);
        LinearVelocity += dt * worldForce / mass; //normal term

        AngularVelocity += dt * worldTorque / inertia;

        LinearVelocity  *= (1 - linearDrag * dt);
        AngularVelocity *= (1 - angularDrag * dt);
        if (!UnderSimulation)
        {
            AngularVelocity = 0;
        }
        if (IsStatic == false)
        {
            transform.Translate(transform.InverseTransformDirection(LinearVelocity) * dt);
            transform.Rotate(0, 0, AngularVelocity * dt * 180 / Mathf.PI);
        }
    }
Beispiel #24
0
    //Determine if a world point exists in the
    //mesh
    public bool ContainsWorldPoint(ref Vector3 worldPoint, ref int[] indices, ref Vector3[] vertices)
    {
        bool containsWorldPoint = false;
        //First do a broad phase contains point detection
        //using AABB contains point method
        MeshRenderer meshRenderer = GetComponent <MeshRenderer>();
        AABB         aabb         = GetComponent <AABB>();
        Vector3      center       = Vector3.zero;

        aabb.SetCenter(ref center);
        Vector3 extents = meshRenderer.bounds.extents;

        aabb.SetHalfExtent(ref extents);

        directionVector = center - worldPoint;

        if (aabb.ContainsPoint(ref worldPoint))
        {
            startPoint = worldPoint;

            int  numberOfTriangles            = indices.Length / 3;
            int  index                        = 0;
            int  numberOfRayCastHits          = 0;
            bool isWorldPointSameAsMeshVertex = false;
            for (int i = 0; i < numberOfTriangles; i++)
            {
                int a = indices[index];
                index++;
                int b = indices[index];
                index++;
                int c = indices[index];

                Vector3 aVector = vertices[a];
                Vector3 bVector = vertices[b];
                Vector3 cVector = vertices[c];

                //Check to see if the world point is same as one of the mesh
                //vertices
                //If it is then, exit out and simply return true
                if (worldPoint == aVector ||
                    worldPoint == bVector ||
                    worldPoint == cVector)
                {
                    isWorldPointSameAsMeshVertex = true;
                    break;
                }

                bool hit = CustomPhysics.RayCastHit(ref startPoint, ref directionVector, ref aVector, ref bVector, ref cVector);
                if (hit)
                {
                    numberOfRayCastHits++;
                }
            }

            //If it hits once or none, then we know the point is inside the mesh
            //Also if the point is the mesh vertex, we consider that inside the mesh as
            //well
            if (numberOfRayCastHits == 0 ||
                numberOfRayCastHits == 1 ||
                isWorldPointSameAsMeshVertex)
            {
                containsWorldPoint = true;
            }
            //If it hits more than once, then we know the point is outside the mesh
            else if (numberOfRayCastHits > 1)
            {
                containsWorldPoint = false;
            }
        }
        Debug.Log("contains point" + worldPoint + " " + containsWorldPoint);
        return(containsWorldPoint);
    }
Beispiel #25
0
 private void Awake()
 {
     _playerBody = GetComponent <CustomPhysics>();
     _spawnPos   = gameObject.transform.position;
     GameObject.Find("InputController").GetComponent <InputController>().Reinitiate();
 }