Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 awplays49 · Sep 19, 2015 at 09:38 PM · debuglogcapsulecast

CapsuleCast not registering

I have a controller handler that I want to make capsule collision with, but my capsule cast debug isn't even launching?

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent (typeof (CapsuleCollider))]
 public class PlayerControllerHandler : MonoBehaviour {
 
     public LayerMask collisionMask;
     private CapsuleCollider cc;
     public int collisions;
     
     void Start () {
         cc = GetComponent <CapsuleCollider> ();
     }
     
     public void Move (Vector3 velocity) {
         Collide (ref velocity);
         transform.Translate (velocity);
     }
     
     void Collide (ref Vector3 velocity) {
         Vector3 point1 = transform.TransformPoint (cc.center + Vector3.down * cc.radius);
         Vector3 point2 = transform.TransformPoint (cc.center + Vector3.up * cc.radius);
         Debug.Log (point1 + " " + point2);
         float rayDistance = velocity.magnitude;
         RaycastHit hit;
         if (Physics.CapsuleCast (point1, point2, cc.radius, velocity, out hit, rayDistance))
         {
             Debug.Log ("Collision");
             if (Mathf.Abs (transform.position.x - hit.point.x) < Mathf.Abs (velocity.x))
             {
                 collisions ++;
                 velocity.x = transform.position.x - hit.point.x;
             }
             if (Mathf.Abs (transform.position.y - hit.point.y) < Mathf.Abs (velocity.y))
             {
                 collisions ++;
                 velocity.y = transform.position.y - hit.point.y;
             }
             if (Mathf.Abs (transform.position.z - hit.point.z) < Mathf.Abs (velocity.z))
             {
                 collisions ++;
                 velocity.z = transform.position.z - hit.point.z;
             }        
         }
     }
 }
 
Comment
Add comment · Show 5
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
avatar image hexagonius · Sep 19, 2015 at 11:30 PM 0
Share

which debug? Is $$anonymous$$ove called somewhere? Is anything close enough?

avatar image awplays49 · Sep 19, 2015 at 11:34 PM 0
Share

@hexagonius my mistake, there is another script involved.

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent (typeof (PlayerControllerHandler))]
 public class PlayerController : $$anonymous$$onoBehaviour {
 
     public float gravity;
     public float moveSpeed;
     private Vector3 velocity;
     private float currentGravity;
     private PlayerControllerHandler pch;
     
     void Start () {
         pch = GetComponent <PlayerControllerHandler> ();
     }
     
     void Update () {
         currentGravity = velocity.y;
         velocity = Vector3.zero;
         velocity.y = currentGravity;
         if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.W))
         {
             velocity += transform.forward;
         }
         else if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.A))
         {
             velocity -= transform.right;
         }
         if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.D))
         {
             velocity += transform.right;
         }
         else if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.S))
         {
             velocity -= transform.forward;
         }
         velocity.y += gravity * Time.deltaTime;
         pch.$$anonymous$$ove (velocity * Time.deltaTime);
     }
 }
 
avatar image hexagonius · Sep 20, 2015 at 09:05 AM 0
Share

how far should the sweep go? To me the distance (velocity * Time.deltaTime) looks quite short.

avatar image awplays49 · Sep 20, 2015 at 12:59 PM 0
Share

@hexagonius I think that should be correct, because that's how far the character is predicted to go next frame.

avatar image awplays49 · Sep 20, 2015 at 01:23 PM 0
Share

@hexagonius I managed to somewhat fix the issue (in some ways) in the way that he no longer jitters higher and higher, but now jitters and the jitter dissolves. I'm not sure why the issue isn't completely gone.

New script:

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent (typeof (CapsuleCollider))]
 public class PlayerControllerHandler : $$anonymous$$onoBehaviour {
 
     public Layer$$anonymous$$ask collision$$anonymous$$ask;
     private CapsuleCollider cc;
     public int collisions;
     public float skinWidth;
     
     void Start () {
         cc = GetComponent <CapsuleCollider> ();
     }
     
     public void $$anonymous$$ove (Vector3 velocity) {
         Collide (ref velocity);
         transform.Translate (velocity);
     }
     
     void Collide (ref Vector3 velocity) {
         Vector3 point1 = transform.TransformPoint (cc.center + Vector3.down * cc.radius);
         Vector3 point2 = transform.TransformPoint (cc.center + Vector3.up * cc.radius);
         Debug.Log (point1 + " " + point2);
         float rayDistance = velocity.magnitude + skinWidth;
         float directionX = $$anonymous$$athf.Sign (velocity.x);
         float directionY = $$anonymous$$athf.Sign (velocity.y);
         float directionZ = $$anonymous$$athf.Sign (velocity.z);
         RaycastHit hit;
         Debug.DrawRay (point1, velocity, Color.red, rayDistance);
         if (Physics.CapsuleCast (point1, point2, cc.radius, velocity, out hit, rayDistance))
         {
             Debug.Log ("Collision");
             if ($$anonymous$$athf.Abs (transform.position.x - hit.point.x) < $$anonymous$$athf.Abs (velocity.x))
             {
                 collisions ++;
                 velocity.x = ($$anonymous$$athf.Abs (hit.point.x - transform.position.x) - skinWidth) * directionX;
             }
             if ($$anonymous$$athf.Abs (transform.position.y - hit.point.y) < $$anonymous$$athf.Abs (velocity.y))
             {
                 collisions ++;
                 velocity.y = ($$anonymous$$athf.Abs (hit.point.y - transform.position.y) - skinWidth) * directionY;
             }
             if ($$anonymous$$athf.Abs (transform.position.z - hit.point.z) < $$anonymous$$athf.Abs (velocity.z))
             {
                 collisions ++;
                 velocity.z = ($$anonymous$$athf.Abs (hit.point.z - transform.position.z) - skinWidth) * directionZ;
             }        
         }
     }
 }
 

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

28 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is there a way to set Unity to write message log when the calculation has Infinity or NaN? 3 Answers

Have my debug log saved to a .log file in build. 2 Answers

Debug.Log Override? 3 Answers

Reading the profiler log 0 Answers

Debug.Log is causing an Assert 2 Answers


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