public void OnCollision(CollObject myObj, CollObject theirObj) { foreach (Hitbox attack in Hitboxes) { if (attack.HitID == myObj.HitID) { attack.enabled = false; } } }
public void CreateHitbox(Hitbox box) { CollObject attackBox = new CollObject(colliderID, box.HitID, this, new Vector2(this.transform.position.x + (viewDirection * box.PosX), this.transform.position.y + box.PosY), box.Radius, box.Type, box.enabled); attackBox.properties = new System.Collections.Generic.Dictionary <PropertyType, int>(); foreach (AttackProperty prop in box.Properties) { attackBox.properties.Add(prop.Type, prop.Value); } managerCollection.GetComponent <CollisionManagerScript>().AddCollBox(attackBox); }
bool Collider.OnCollision(CollObject myObj, CollObject theirObj) { if (myObj.type == CollisionType.Hittable) { if (currentState == State.Blocking || currentState == State.Blockstun) { if (theirObj.properties.TryGetValue(PropertyType.Blockstun, out stunTime)) { horSpeed = 0; currentState = State.Blockstun; /*if(animation) * { * animation["block"].speed = animation["block"].length / (stunTime/60.0f); * animation.Play("block"); * }*/ } Debug.Log(name + " says: Not this time!"); } else { if (theirObj.properties.TryGetValue(PropertyType.Hitstun, out stunTime)) { horSpeed = 0; currentState = State.Hitstun; if (animations) { animations["hit"].time = 0; animations["hit"].speed = animations["hit"].length / (stunTime / 60.0f); animations.Play("hit"); } } int dmg = 0; theirObj.properties.TryGetValue(PropertyType.Damage, out dmg); health -= dmg; } //disable our hurtboxes for the rest of this frame return(false); } else if (myObj.type == CollisionType.Hit) { currentMove.OnCollision(myObj, theirObj); } return(true); }
// Update is called once per frame void FixedUpdate() { //Debug.Log("Circles: " + myCircleList.Count); for (int i = 0; i < myCircleList.Count; i++) { for (int j = i; j < myCircleList.Count; j++) { CollisionCheck(myCircleList[i], myCircleList[j]); //CollisionCheck(myCircleList[i], myCircleList[j], myCircleList.Count > 8); } } #if RENDERHITSPHERES foreach (GameObject sphere in myRenderSpherePool) { sphere.GetComponent <Renderer>().enabled = false; } for (int i = 0; i < myCircleList.Count; i++) { while (myRenderSpherePool.Count <= i) { GameObject newSphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); myRenderSpherePool.Add(newSphere); } CollObject obj = myCircleList[i]; GameObject sphere = myRenderSpherePool[i]; //sphere.transform.localScale = Vector3(); sphere.transform.position = new Vector3(obj.pos.x, obj.pos.y, 0); sphere.transform.localScale = new Vector3(obj.radius, obj.radius, obj.radius); sphere.GetComponent <Renderer>().enabled = true; if (obj.type == CollisionType.Hit) { sphere.GetComponent <Renderer>().material.color = Color.red; } if (obj.type == CollisionType.Hittable) { sphere.GetComponent <Renderer>().material.color = Color.green; } } #endif myCircleList.Clear(); }
void CollisionCheck(CollObject obj, CollObject otherObj, bool log) { if (log) { Debug.Log("Obj.enabled: " + obj.enabled + " ID: " + obj.ID + " Type: " + obj.type); Debug.Log("OtherObj.enabled: " + otherObj.enabled + " ID: " + otherObj.ID + " Type: " + otherObj.type); } if (!obj.enabled || !otherObj.enabled) { return; } if (obj.ID == otherObj.ID) { return; } //one object has to be Hit and the other has to be Hittable if (!(obj.type == CollisionType.Hit && otherObj.type == CollisionType.Hittable || obj.type == CollisionType.Hittable && otherObj.type == CollisionType.Hit)) { return; } if (log) { Debug.Log("Distance: " + Vector2.Distance(obj.pos, otherObj.pos) + " obj.radius: " + obj.radius + " otherObj.radius: " + otherObj.radius); } if (Vector2.Distance(obj.pos, otherObj.pos) < (obj.radius + otherObj.radius)) { if (log) { Debug.Log("Hit!"); } obj.enabled = obj.collider.OnCollision(obj, otherObj); otherObj.enabled = otherObj.collider.OnCollision(otherObj, obj); } }
// Update is called once per frame void FixedUpdate() { if (currentMove != null && !currentMove.Active()) { currentMove = null; currentState = State.Idle; } if (stunTime > 0) { if (currentMove != null) { currentMove = null; } stunTime--; if (stunTime <= 0) { currentState = State.Idle; } } //MAGIC NUMBERS FOR NOW: FIX //position of hitbox will be read from data later CollObject hurtBox1 = new CollObject(colliderID, this, new Vector2(this.transform.position.x, this.transform.position.y + 1.0f), 2, CollisionType.Hittable); CollObject hurtBox2 = new CollObject(colliderID, this, new Vector2(this.transform.position.x, this.transform.position.y + 3.0f), 2, CollisionType.Hittable); CollObject hurtBox3 = new CollObject(colliderID, this, new Vector2(this.transform.position.x, this.transform.position.y + 5.0f), 2, CollisionType.Hittable); CollObject hurtBox4 = new CollObject(colliderID, this, new Vector2(this.transform.position.x, this.transform.position.y + 7.0f), 2, CollisionType.Hittable); managerCollection.GetComponent <CollisionManagerScript>().AddCollBox(hurtBox1); managerCollection.GetComponent <CollisionManagerScript>().AddCollBox(hurtBox2); managerCollection.GetComponent <CollisionManagerScript>().AddCollBox(hurtBox3); managerCollection.GetComponent <CollisionManagerScript>().AddCollBox(hurtBox4); if (currentState == State.Attacking) { if (currentMove != null) { currentMove.Update(); } } DoMovement(); //Animations if (animations == null) { return; } if (currentState == State.Idle) { currentMove = this.inputReader.InputtedMove(); if (currentMove != null) { horSpeed = 0; currentState = State.Attacking; currentMove.Do(this); } } if (currentState == State.Idle) { if (Input.GetButton(buttonBlock)) { horSpeed = 0; animations.Play("block"); currentState = State.Blocking; } } else if (currentState == State.Blocking) { if (!Input.GetButton(buttonBlock)) { currentState = State.Idle; } } if (currentState == State.Idle) { if (horSpeed != 0) { animations.Play("walk"); } else { animations.Play("idle"); } } }
public void AddCollBox(CollObject obj) { myCircleList.Add(obj); }
void CollisionCheck(CollObject obj, CollObject otherObj) { CollisionCheck(obj, otherObj, false); }