static void ContactPoint2D_otherCollider(JSVCall vc)
    {
        UnityEngine.ContactPoint2D _this = (UnityEngine.ContactPoint2D)vc.csObj;
        var result = _this.otherCollider;

        JSMgr.datax.setObject((int)JSApi.SetType.Rval, result);
    }
 static public int constructor(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.ContactPoint2D o;
         o = new UnityEngine.ContactPoint2D();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Exemple #3
0
    protected void OnCollisionStay2D(Collision2D collision)
    {
        ContactPoint2D realContact = new ContactPoint2D();
        foreach (ContactPoint2D contact in collision.contacts)
        {
            if (Physics2D.Raycast(contact.point, -transform.up, 0.1f).collider != null)
                realContact = contact;
        }
        if (realContact.normal != default(Vector2))
        {
            if (!m_terrain.Contains(collision.gameObject))
            {
                m_terrain.Add(collision.gameObject);

            }
            SurfaceContact = realContact;
        }
        else
        {
            m_terrain.Remove(collision.collider.gameObject);
            if (m_terrain.Count == 0)
            {
                SurfaceContact = new ContactPoint2D();
            }
        }
    }
    static void ContactPoint2D_normal(JSVCall vc)
    {
        UnityEngine.ContactPoint2D _this = (UnityEngine.ContactPoint2D)vc.csObj;
        var result = _this.normal;

        JSApi.setVector2S((int)JSApi.SetType.Rval, result);
    }
Exemple #5
0
 protected void OnCollisionExit2D(Collision2D collision)
 {
     m_terrain.Remove(collision.gameObject);
     if (m_terrain.Count == 0)
     {
         SurfaceContact = new ContactPoint2D();
     }
 }
Exemple #6
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.ContactPoint2D o;
         o = new UnityEngine.ContactPoint2D();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
	static public int constructor(IntPtr l) {
		try {
			UnityEngine.ContactPoint2D o;
			o=new UnityEngine.ContactPoint2D();
			pushValue(l,true);
			pushValue(l,o);
			return 2;
		}
		catch(Exception e) {
			return error(l,e);
		}
	}
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.ContactPoint2D o;
         o=new UnityEngine.ContactPoint2D();
         pushValue(l,o);
         return 1;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
Exemple #9
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.ContactPoint2D o;
         o = new UnityEngine.ContactPoint2D();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
        private void Collide(Entity bullet, ContactPoint2D[] contacts)
        {
            foreach (var contact in contacts)
            {
                var damageable = _damageable.GetEntities().FirstOrDefault(e => e != bullet &&
                                             e.view.gameObject == contact.otherCollider.gameObject);

                if (damageable != null)
                {
                    damageable.ReplaceHitpoints(damageable.hitpoints.hp - 1);
                    bullet.isDestroying = true;
                }
            }
        }
 static int GetContact(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         UnityEngine.Collision2D obj = (UnityEngine.Collision2D)ToLua.CheckObject <UnityEngine.Collision2D>(L, 1);
         int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
         UnityEngine.ContactPoint2D o = obj.GetContact(arg0);
         ToLua.PushValue(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
    private void gushBlood(ContactPoint2D[] contacts)
    {
        foreach (var contact in contacts)
        {
            Vector3 contact3d = new Vector3(contact.point.x, contact.point.y, 0);

            // Set the sorting layer of the particle system. http://answers.unity3d.com/questions/579490/unity-43-particle-system-not-visible-in-2d-mode.html
            bloodsplat.renderer.sortingLayerName = "Foreground";
            bloodsplat.renderer.sortingOrder = 2;
            var bloodParticles = Instantiate(bloodsplat, contact3d, this.transform.rotation) as ParticleSystem;
            Destroy(bloodParticles.gameObject, 3.0f);

            if (audio.isPlaying == false)
                playAudio(Squirt);
        }
    }
	// returns true if this gameobject was attached and for the first time
	protected bool Attach(GameObject collidedGameObject, bool mustHavePriority, ContactPoint2D contactPoint){

		bool firstTimeAttached = false;

		AttachScript collidedAttach = collidedGameObject.GetComponent<AttachScript>();

		// The AttachScripts of the highest members of both hiarchies
		AttachScript myHighestAttach = gameObject.transform.root.gameObject.GetComponent<AttachScript>();
		AttachScript collidedHighestAttach = collidedGameObject.transform.root.gameObject.GetComponent<AttachScript>();

		if (collidedAttach != null){
			// If an object with hiarchy authority collides with a non-authority object and the authority object
			// gets collision resolved first, then the non-authority object will not have its collision resolution get
			// past this point becuase it was given hiarchy authority when the other object resolved its collision
			if ((!(collidedHighestAttach.topOfHiarchy == true && myHighestAttach.topOfHiarchy == true)))
			{

				firstTimeAttached = HandleGameObjectOnAttach(this);

				// This if statement will only be true for one of the two collided objects, so that the code will be ran only once from one perspective
				// This if statement also stops the parent of the collided object from making it any farther
				if ((gameObject.transform.position.x + gameObject.transform.position.y >
					collidedGameObject.transform.position.x + collidedGameObject.transform.position.y ||
					mustHavePriority == true) &&
					AmInCollision(contactPoint))
				{

					// If the collided object does not have hiarchy authority and I do
					if (collidedHighestAttach.topOfHiarchy == false && myHighestAttach.topOfHiarchy == true)
					{
						ParentGameObjectsTogether(gameObject, collidedGameObject);
						// Handle the other objects on attach call because it won't do it its self because 
						// it's hiarachy authority is now true and won't make it through it's collision resolution method
						HandleGameObjectOnAttach(collidedGameObject.GetComponent<AttachScript>());
					}
					// If either this object has hiarchy authority or neither does
					else 
					{
						ParentGameObjectsTogether(collidedGameObject, gameObject);
					}
				}
			}
		}
		return firstTimeAttached;
	}
 void OnCollisionEnter2D(Collision2D collision)
 {
     if(collision.gameObject.tag == "Enemy") {
         theEnemy = collision.gameObject;
         fb = theEnemy.GetComponent<FishyBehavior>();
         dmg = fb.bitePain;
         health = fb.healthSystemAmount;
         theEnemy.GetComponent<HealthSystem>().removeHealth(dmg);
         thePlayer.GetComponent<HealthSystem>().addHealth(health);
         hs.startShake();
         ah.playEat();
         contactPoint = collision.contacts[collision.contacts.Length-1];
         Instantiate(gibs, contactPoint.point, Quaternion.identity);
         if(Time.time > nextChain){
             nextChain = Time.time + chainRate;
             aet.chainPlay();
         }
     }
 }
Exemple #15
0
 //float m_colliderRatio;
 protected override void Start()
 {
     Level.CurrentLevel.MobSpawned();
     //m_colliderRatio = GetComponent<Collider2D>().bounds.extents.y / GetComponent<Collider2D>().bounds.extents.x;
     SurfaceContact = new ContactPoint2D();
     //SurfaceContact.normal = Vector2.up;
     Targets = new List<GameObject>();
     Stopped = false;
     SetStrategy(GoblinFloatStrategy.Instance());
 }
 static int _CreateContactPoint2D(IntPtr L)
 {
     LuaScriptMgr.CheckArgsCount(L, 0);
     ContactPoint2D obj = new ContactPoint2D();
     LuaScriptMgr.PushValue(L, obj);
     return 1;
 }
	// Returns true if this gameobject's collider was involed in the given contact point of a collision
	private bool AmInCollision(ContactPoint2D contactPoint)
	{
		bool isInCollision = false;
		if (contactPoint.collider.gameObject == gameObject ||
			contactPoint.otherCollider.gameObject == gameObject)
		{
			isInCollision = true;
		}

		return isInCollision;
	}
	private void AddForceToRigidGivenVelo(Rigidbody2D target, Rigidbody2D fromRigid, ContactPoint2D atPosition){
		Vector2 force = new Vector2(0.5f * fromRigid.mass * Mathf.Pow(fromRigid.velocity.x,2f), 
									0.5f * fromRigid.mass * Mathf.Pow(fromRigid.velocity.y,2f));
		
		target.AddForceAtPosition(force, atPosition.point);
	}
Exemple #19
0
 static public int get_otherCollider(IntPtr l)
 {
     UnityEngine.ContactPoint2D o = (UnityEngine.ContactPoint2D)checkSelf(l);
     pushValue(l, o.otherCollider);
     return(1);
 }
Exemple #20
0
 static public int get_normal(IntPtr l)
 {
     UnityEngine.ContactPoint2D o = (UnityEngine.ContactPoint2D)checkSelf(l);
     pushValue(l, o.normal);
     return(1);
 }
Exemple #21
0
	public void ObstacleCollision(ContactPoint2D[] contacts)  {
		stepsSinceWall = 0;

		ContactPoint2D contact = contacts[0];
		bool yAxis = Mathf.Abs(direction.y) > Mathf.Abs(direction.x);
		bool wallYAxis = false;
		bool wallXAxis = false;

		//wall above
		if (contact.point.y > position.y && direction.y > 0)
			wallYAxis = true;
		//wall below
		if (contact.point.y < position.y && direction.y < 0)
			wallYAxis = true;
		//wall right
		if (contact.point.x > position.x && direction.x > 0)
			wallXAxis = true;
		//wall left
		if (contact.point.x < position.x && direction.x < 0)
			wallXAxis = true;
		
		if (wallYAxis && wallXAxis) {
			if (yAxis)
				direction.y *= -1;
			else
				direction.x *= -1;
		} else {
			if (wallXAxis)
				direction.x *= -1;
			if (wallYAxis)
				direction.y *= -1;
		}

		TakeStep ();
	}
Exemple #22
0
 // Used when two collision events fire on the same frame (haven't tested > 2)
 //  determines whether this contact is the desirable one, based on player movement
 // h - direction of horizontal input (from Input.GetAxis)
 // contact - the collision point to test
 // other - the other collision point detected in the same frame
 bool shouldShiftJoint(float h, ContactPoint2D contact, ContactPoint2D other)
 {
     return (h > 0 && ((contact.point.x > transform.position.x && other.normal.y > 0) ||
                   	  (contact.point.x < transform.position.x && other.normal.y < 0) ||
                       (contact.point.y < transform.position.y && other.normal.x > 0) ||
                       (contact.point.y > transform.position.y && other.normal.x < 0)))
         || (h < 0 && ((contact.point.x < transform.position.x && other.normal.y > 0) ||
                       (contact.point.x > transform.position.x && other.normal.y < 0) ||
                       (contact.point.y > transform.position.y && other.normal.x > 0) ||
                       (contact.point.y < transform.position.y && other.normal.x < 0)));
 }
 // Return if a contact is connected to the ground
 public bool CheckContactWithGround(ContactPoint2D contact)
 {
     return contact.normal.y < 0.5f;
 }
Exemple #24
0
    void SpiderCollisionCheck(Collision2D collision)
    {
        bool movingPlatformFlag = false;
        if (collision.gameObject.GetComponent<OneWay>() != null
            || collision.gameObject.GetComponent<Spring>() != null)
        {	//avoids the weird behavior of certain objects by ignoring them
            //crawling on a spring or one-way platform should be undefined anyway
            ForceQuit();
            return;
        }
        if (collision.collider.GetComponent<MovingPlatform>() != null ||
            (collision.collider.transform.childCount > 0 &&
         	 collision.collider.transform.GetChild(0).GetComponent<MovingPlatform>() != null))
        {
            movingPlatformFlag = true;
        }

        collisionInst++;
        float h = Input.GetAxis("Horizontal");
        if (collisionInst == 1 || shouldShiftJoint(h, collision.contacts[0], otherCollide))
        {
            if (collisionInst == 1)
                otherCollide = collision.contacts[0];

            lastCollision = collision;
            if (joint == null && !isConnected) {
                joint = gameObject.AddComponent("SpringJoint2D") as SpringJoint2D;

                isConnected = true;
                framesSinceDisconnected = 0;

                joint.anchor = new Vector2(0f,0f);
                joint.collideConnected = true;
                joint.dampingRatio = dampingRatio;
                joint.frequency = stickiness;

                if (movingPlatformFlag)
                {
                    joint.connectedBody = collision.rigidbody;
                    joint.connectedAnchor = collision.collider.transform.InverseTransformPoint(
                        collision.contacts[0].point);
                    joint.distance = (collision.contacts[0].point - new Vector2(transform.position.x, transform.position.y)).magnitude;
                }
                else
                {
                    joint.connectedBody = null;
                    joint.connectedAnchor = collision.contacts[0].point;
                    joint.distance = jointDistance;
                    GetComponent<PlayerBallControl>().spiderOnMovingPlatform = false;
                }

            } else if (joint != null) {
                joint.enabled = true;
                joint.anchor = new Vector2(0f,0f);

                framesSinceDisconnected = 0;

                if (movingPlatformFlag)
                {
                    joint.connectedBody = collision.rigidbody;
                    joint.connectedAnchor = collision.collider.transform.InverseTransformPoint(
                        collision.contacts[0].point);
                    joint.distance = (collision.contacts[0].point - new Vector2(transform.position.x, transform.position.y)).magnitude;
                }
                else
                {
                    joint.connectedBody = null;
                    joint.connectedAnchor = collision.contacts[0].point;
                    GetComponent<PlayerBallControl>().spiderOnMovingPlatform = false;
                }
            }
        }
        if (joint != null)
            Debug.DrawLine(new Vector3(joint.connectedAnchor.x, joint.connectedAnchor.y, 0f), transform.position, Color.red);
    }
Exemple #25
0
    Vector2 TreatColPoints(ContactPoint2D[] pts)
    {
        float x =0;
        float y =0;
        int xc = 0;
        int yc = 0;
        foreach(ContactPoint2D point in pts)
        {
            x = x + point.point.x;
            xc ++;
            y = y + point.point.y;
            yc ++;
        }
        x = x/xc;
        y = y/yc;

        Vector2 finalpoint = new Vector2(x,y);

        Vector3 fp = new Vector3(finalpoint.x,finalpoint.y,this.transform.position.z);

        fp = this.transform.InverseTransformPoint(fp);
        finalpoint = new Vector2(fp.x,fp.y);

        return finalpoint;
    }
Exemple #26
0
 public int compare(ContactPoint2D c1, ContactPoint2D c2)
 {
     float       diff = Vector3.Distance(this.basePos, c1.point) - Vector3.Distance(this.basePos, c2.point);
     if (0 > diff) return -1; else if (0 < diff) return 1; return 0;
 }
Exemple #27
0
    void OnCollisionEnter2D(Collision2D col)
    {
        if (col.gameObject.tag == "Hazard" || col.gameObject.tag == "Enemy") {
            contact = col.contacts [0];
            timeHit = Time.time;
            Hit = true;
            noControl = true;
            StartCoroutine("Blink");

            //Allow player to pass thorugh enemies
            foreach (GameObject enemy in enemies) {
                Physics2D.IgnoreCollision (this.GetComponent<Collider2D>(), enemy.GetComponent<Collider2D>(), true);
            }
        }
    }