void Start() { limb = GetComponentInParent <Limb>(); controller = GetComponentInParent <StickmanController>(); ig = GetComponentInParent <IgnoreCollision>(); var circleColl = gameObject.AddComponent <CircleCollider2D>(); circleColl.radius = .05f; coll = circleColl; if (ig) { ig.IgnoreCollider(coll); } rb = GetComponent <Rigidbody2D>(); parent = transform; while (parent.parent) { parent = parent.parent; } mask = ~LayerMask.GetMask("Moveable"); joint = gameObject.AddComponent <FixedJoint2D>(); joint.enabled = false; }
public void Start() { ignore = GetComponentInParent <IgnoreCollision> (); if (flip) { StartCoroutine(Flipper()); } }
private void OnEnable() { identity = GetComponentInParent <NetIdentity>(); evtPull = identity.RegisterEvent(OnPull); if (NetGame.isServer) { if (joint == null) { joint = CreateJoint(); } anchor = axis.TransformPoint(Vector3.forward); totalTravel = 0f; if (groundedIgnoreCollider != null) { IgnoreCollision.Ignore(base.transform, groundedIgnoreCollider); } } }
// Update is called once per frame void Update() { if (Time.time > nextSpawn) { if (numberOfEnemies <= maxEnemies) { nextSpawn = Time.time + spawnRate; randomX = Random.Range(minX, maxX); placeToSpawn = new Vector2(randomX, transform.position.y); numberOfEnemies++; GameObject obj = Instantiate(enemy, placeToSpawn, Quaternion.identity) as GameObject; obj.GetComponent <Collider2D>().enabled = false; obj.GetComponent <Collider2D>().enabled = true; IgnoreCollision ignore = obj.GetComponent <IgnoreCollision>(); ignore.others.Add(obj.GetComponent <Collider2D>()); ignore.other = Hero.Instance.GetComponent <Collider2D>(); ignore.ignoreCollision(); Collider2D colliderChild = obj.GetComponentInChildren <Collider2D>(); GameObject[] edges = GameObject.FindGameObjectsWithTag("Edge"); foreach (GameObject edge in edges) { if (edge.name.ToLower().Contains("left")) { obj.GetComponent <Enemy>().leftEdge = edge.GetComponent <Transform>(); } if (edge.name.ToLower().Contains("right")) { obj.GetComponent <Enemy>().rightEdge = edge.GetComponent <Transform>(); } } colliderChild.enabled = false; colliderChild.enabled = true; } } }
public void FixedUpdate() { if (joint == null || NetGame.isClient || ReplayRecorder.isPlaying) { return; } Vector3 vector = axis.TransformPoint(Vector3.forward); float num = (vector - anchor).magnitude - 0.1f; if (!(num > 0f)) { return; } totalTravel += num / (breakAngleTravel * ((float)Math.PI / 180f)); anchor = Vector3.MoveTowards(anchor, vector, num); if (totalTravel > 1f) { NetStream netStream = identity.BeginEvent(evtPull); identity.EndEvent(); OnPull(null); UnityEngine.Object.Destroy(joint); GetComponent <Rigidbody>().angularDrag = 0.05f; GetComponent <Rigidbody>().useGravity = true; if (groundedIgnoreCollider != null) { IgnoreCollision.Unignore(base.transform, groundedIgnoreCollider); } } else { joint.angularYZDrive = new JointDrive { positionSpring = 0f, positionDamper = holdDamper * (1f - totalTravel), maximumForce = float.PositiveInfinity }; } }
void HandleInput() { if (InputGoLeft()) { GetComponent<Rigidbody2D>().AddForce(new Vector2(-movementSpeed, 0), ForceMode2D.Force); } if (InputGoRight()) { GetComponent<Rigidbody2D>().AddForce(new Vector2(movementSpeed, 0), ForceMode2D.Force); } if ((InputJump() && !isInJump && GetComponent<Rigidbody2D>().velocity.y < epsilon) || forcedJump) { isInJump = true; if (Input.GetKey(KeyCode.DownArrow) && !isCurrentGroundSolid) { //fall from platform IgnoreCollision timedCollision = new IgnoreCollision(); timedCollision.coll1 = currentGround; timedCollision.coll2 = GetComponent<BoxCollider2D>(); timedCollision.timeLeft = collideIgnoreTime; collisions.Add(timedCollision); Physics2D.IgnoreCollision(currentGround, GetComponent<BoxCollider2D>(), true); } else { //regular jump GetComponent<Rigidbody2D>().AddForce(new Vector2(0, jumpHeight * jumpMultiplier), ForceMode2D.Impulse); } jumpMultiplier = 1.0f; forcedJump = false; currentGround = null; } }
void IPreReset.PreResetState(int checkpoint) { IgnoreCollision.Ignore(base.transform, ignoreHat); }
private void OnJointBreak(float breakForce) { IgnoreCollision.Unignore(base.transform, ignoreHat); }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "platform") { var colliders = other.gameObject.GetComponents<EdgeCollider2D>(); Debug.Assert(colliders.Length == 2, "There should be exactly 2 colliders, trigger and nontrigger!"); foreach (EdgeCollider2D nonTriggerCollider in colliders) { if (!nonTriggerCollider.isTrigger) { //we have found non-trigger collider float topPos = (transform.position.y + GetComponent<BoxCollider2D>().size.y / 2); float diffY = Mathf.Abs(nonTriggerCollider.attachedRigidbody.position.y - topPos); if (diffY < epsilon) { //we're jumping from down IgnoreCollision timedCollision = new IgnoreCollision(); timedCollision.coll1 = nonTriggerCollider; timedCollision.coll2 = GetComponent<BoxCollider2D>(); timedCollision.timeLeft = collideIgnoreTime; collisions.Add(timedCollision); Physics2D.IgnoreCollision(nonTriggerCollider, GetComponent<BoxCollider2D>(), true); } } } } }