public void Stick(IStickProperty property) { if (property.IsEnable) { int normalX = Mathf.RoundToInt(this.normalHit.x); int normalY = Mathf.RoundToInt(this.normalHit.y); if (Math.Abs(normalX) == 1 || normalY == -1) { this.stickTime = 0.0f; this.isStick = true; } else if (normalY == 1) { this.isGrounded = true; } else { this.stickTime = 0.0f; this.isStick = true; } //Vector3 offset = (this.transform.position - this.hitPoint); //this.transform.position = this.hitPoint + offset; this.direction = Vector3.zero; } }
private void OnCollision(GameObject obj) { Debug.Log("Checking collisions"); //Get the component of the object we collided IStickProperty stickProperty = obj.GetComponent <IStickProperty>(); IBounceProperty bounceProperty = obj.GetComponent <IBounceProperty>(); IFrictionProperty frictionProperty = obj.GetComponent <IFrictionProperty>(); ISlipProperty slipProperty = obj.GetComponent <ISlipProperty>(); if (Math.Abs(Vector3.Angle(this.normalHit, this.finalDirection)) > 90.0f) { if (bounceProperty != null) { Debug.Log("Bounce"); this.Bounce(new Collision(), bounceProperty); } else if (stickProperty != null && !this.isGrounded && !this.isStick) { Debug.Log("Stick"); this.Stick(stickProperty); } } else if (frictionProperty != null && this.direction != Vector3.zero) { Debug.Log("Friction"); this.Friction(frictionProperty); } if (slipProperty != null && !this.isSlip) { Debug.Log("Slip"); this.Slip(slipProperty); } }
private void OnCollisionEnter(Collision collision) { Debug.Log("Collision !"); switch (collision.gameObject.tag) { case GameObjectsTags.Stick: //Stick Behaviour IStickProperty stickProperty = collision.gameObject.GetComponent <StickProperty>(); if (stickProperty != null) { if (stickProperty.IsEnable) { Debug.Log("Stick !"); this.Stick(collision, stickProperty); } } break; case GameObjectsTags.Bounce: //Bounce Behaviour IBounceProperty bounceProperty = collision.gameObject.GetComponent <BounceProperty>(); if (bounceProperty != null) { if (bounceProperty.IsEnable) { Debug.Log("Bounce !"); this.Bounce(collision, bounceProperty); } } break; case GameObjectsTags.Slip: //Slip Behaviour this.rigidbody.useGravity = false; break; default: break; } }
public void Stick(Collision collision, IStickProperty property) { throw new NotImplementedException(); }
public void Stick(Collision collision, IStickProperty property) { this.isStick = true; this.rigidbody.useGravity = false; this.rigidbody.velocity = Vector3.zero; }