Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Malik Ehtasham · Mar 06, 2013 at 06:21 AM · javascriptcollisioncharactercontrollercapsulecollider

Collision Detection in Capsule Collider

I am working on 3D fighting game.I have two character with their animation.I have applied character controller and character controller script which i have customized. I have two button one to move farword and one to move backword..And four button to play different animation just like make a punch, hit a leg etc. Upto that its work perfactly fine. Now I have use capsule object with their capsule collider as a child of different bones. Like i have place one capsule object with their collider the child of left hand bone.SO where the bone move that object will move.. I have also place a capusle on the second player body which i place below the head and above the legs its mean it place in the chest erea. I have also used Rigid body having no gravity and onTrigger function clicked in all capsule obects.. Now i want that when my first player hand touch the second player main body in which capsule is place it will call a function.But in the script it will not call..I dont know what is the problem..Can any body guide me. Here is my script

 public function Start() : void {
 f_inAirStartTime = Time.time;
 }
 //Checking if the character hit the ground (collide Below)
 public function IsGrounded () : boolean {
 return (c_collisionFlags & CollisionFlags.CollidedBelow);
 }
 //Getting if the character is jumping or not
 public function IsJumping() : boolean {
 return b_isJumping;
 }
 //Checking if the character is in the air more than the minimum time
 //This function is to make sure that we are falling not walking down slope
 public function IsAir() : boolean {
 return (f_inAirTime > f_minAirTime);
 }
 //Geting if the character is moving backward
 public function IsMoveBackward() : boolean {
 return b_isBackward;
 }
 public function Update() : void {
 //Get Main Camera Transform
 var cameraTransform = Camera.main.transform;
 //Get forward direction of the character
 v3_forward = cameraTransform.TransformDirection(Vector3.forward);
 v3_forward.y = 0; //Make sure that vertical direction equals zero
 // Right vector relative to the character
 // Always orthogonal to the forward direction vector
 v3_right = new Vector3(v3_forward.z, 0, -v3_forward.x);
 
 //Get Horizontal move - rotation
 var f_hor : float ;//= Input.GetAxis("Horizontal");
 if(backword==true)
 {
 f_hor=1;
 backword=false;
 }
 if(farword==true)
 {
 f_hor=-1;
 farword=false;
 }
 
 
 
 
 
 
 
 
 
 
 
 //Get Vertical move - move forward or backward
 var f_ver : float = Input.GetAxis("Vertical");
 //If we are moving backward
 if (f_ver < 0) {
 b_isBackward = true;
 } else {
 b_isBackward = false;
 }
 //Get target direction
 var v3_targetDirection : Vector3 = (f_hor * v3_right) + (f_ver * v3_forward);
 //If the target direction is not zero - that means there is no button pressing
 if (v3_targetDirection != Vector3.zero) {
 //Rotate toward the target direction
 v3_moveDirection = Vector3.Slerp(v3_moveDirection, v3_targetDirection, f_rotateSpeed * Time.deltaTime);
 v3_moveDirection = v3_moveDirection.normalized; //Get only direction by normalizing our target vector
 } else {
 v3_moveDirection = Vector3.zero;
 }
 //Checking if character is on the ground
 if (!b_isJumping) {
 //Holding Shift to run
 //if (Input.GetKey (KeyCode.LeftShift) || Input.GetKey (KeyCode.RightShift)) {
 if(Left_punch_anim){
 
 
 b_isRun = true;
 
 f_moveSpeed = runSpeed;
 //Right_punch_anim=false;
 } else {
 b_isRun = false;
 f_moveSpeed = speed;
 }
 //Press Space to Jump
 if (Input.GetButton ("Jump")) {
 f_verticalSpeed = jumpSpeed;
 b_isJumping = true;
 }
 }
 //Debug.Log(controller.velocity.sqrMagnitude+"magniture");
 
 // Apply gravity
 if (IsGrounded()) {
 f_verticalSpeed = 0.0; //if our character is grounded
 b_isJumping = false; //Checking if our character is in the air or not
 f_inAirTime = 0.0;
 f_inAirStartTime = Time.time;
 } else {
 f_verticalSpeed -= gravity * Time.deltaTime; //if our character in the air
 //Count Time
 f_inAirTime = Time.time - f_inAirStartTime;
 }
 // Calculate actual motion
 var v3_movement : Vector3 = (v3_moveDirection * f_moveSpeed) + Vector3 (0, f_verticalSpeed, 0); // Apply the vertical speed if character fall down
 v3_movement *= Time.deltaTime;
 // Move the controller
 c_collisionFlags = controller.Move(v3_movement);
 //Play animation
 if (b_isJumping) {
 if (controller.velocity.y > 0 ) {
 animation[jumpPoseAnimation.name].speed = jumpAnimationSpeed;
 animation.CrossFade(jumpPoseAnimation.name, 0.1);
 } else {
 animation[fallPoseAnimation.name].speed = fallAnimationSpeed;
 animation.CrossFade(fallPoseAnimation.name, 0.1);
 }
 } else {
 if (IsAir()) { // Fall down
 animation[fallPoseAnimation.name].speed = fallAnimationSpeed;
 animation.CrossFade(fallPoseAnimation.name, 0.1);
 } else {
 if(controller.velocity.sqrMagnitude < 0.1) {
    if(Left_punch_anim)
    {
 
    animation[leftanimAnimation.name].speed = runAnimationSpeed;
 animation.CrossFade(leftanimAnimation.name, 0.5);
 Left_punch_anim=false;
 idlemode=true;
 
    }
    else
    if(Right_punch_anim)
    {
 
    animation[rightanimAnimation.name].speed = runAnimationSpeed;
 animation.CrossFade(rightanimAnimation.name, 0.5);
 Right_punch_anim=false;
 idlemode=true;
 
    }
    else
   { 
 //Debug.Log(controller.velocity.sqrMagnitude+"hjgkjgkjg");
 animation[idleAnimation.name].speed = idleAnimationSpeed;
 animation.CrossFade(idleAnimation.name, 0.1);
 }
 } else { //Checking if the character walks or runs
 if (b_isRun) {
 //Debug.Log("In the run animation");
 animation[leftanimAnimation.name].speed = runAnimationSpeed;
 animation.CrossFade(leftanimAnimation.name, 0.1);
 } else {
 animation[walkAnimation.name].speed = walkAnimationSpeed;
 animation.CrossFade(walkAnimation.name, 0.1);
 }
 }
 }
 }
 if(idlemode)
 {
 
 }
 //Update rotation of the character
 if (v3_moveDirection != Vector3.zero) {
 transform.rotation = Quaternion.LookRotation(v3_moveDirection);
 }
 }
 public function OnControllerColliderHit(hit:ControllerColliderHit)
 {
     //     Debug.Log("Collision have been enter");
     }   
 
 /*public function OnTriggerEnter(other:Collider)
 {
 
 Debug.Log(other.gameObject.name);
 }*/
 public function OnCollisionEnter(other:Collision)
 {
 Debug.Log("collision is enter");
 }
 function OnTriggerEnter(col:Collider)
 {
 Debug.Log(col.gameObject.name); 
 
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Collision Detection 0 Answers

Analysing player metrics help 0 Answers

how to take maya animation file in to unity? 1 Answer

Can someone help me with my script? 0 Answers

Collision no longer occurs after turning off shield (javascript) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges