public void Slip(ISlipProperty property) { //CalculateNewDirection float angle = Vector3.Angle(this.normalHit, this.finalDirection); Vector3 A = Vector3.zero; Vector3 B = this.normalHit; Vector3 M = this.finalDirection; float value = ((B.x - A.x) * (M.y - A.y) - (B.y - A.y) * (M.x - A.x)); // -1 is on the right, 1 is on the left, 0 is on the line. float sign = 0; if (value > 0) { sign = 1; } else { sign = -1; } Vector3 nextDirection = Vector3.Cross(this.normalHit, Vector3.forward).normalized * -sign; Debug.Log("Angle : " + angle + " | sign : " + sign + " | nextDirection : " + nextDirection); Debug.DrawRay(this.transform.position, nextDirection, Color.gray); this.direction = nextDirection * Math.Abs(this.finalDirection.x); this.gravityApplied.y = 0.0f; this.isGrounded = true; //this.isSlip = true; }
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); } }