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 robotmaker01 · Aug 30, 2012 at 10:02 AM · raycastcontrollergroundfloorisgrounded

raycast and isgrounded dont work

i created a control script for my character that uses character controller script(from standards assets). i have a problem:

     var Speed2 = 15;
     var Speed3 = 5;
     var Rota = 50;
     var jumpspeed:float;
     var anim:Animation;
     var gravity=10.0;
     var jumpstep:int=0;
     private var moveDirection : Vector3 = Vector3.zero;
     anim = GetComponent(Animation);
     var forward : Vector3;
     var up : Vector3;
 
     var poshelper:Vector3;
     var poshelper2:Vector3;
     var charp:GameObject;
     var pushPower = 2.0;
     var speedaxis:float;
     var diraxis:float;
     var grounded:boolean;
     var congrounded:boolean;
     public var steps:int=30;
 
     
     
     
     function Awake () {
     charp=GameObject.Find("charp");
     anim.wrapMode = WrapMode.Loop;
     
     
     
 }
     
     
     function Update ()
     {
         var up = transform.TransformDirection(Vector3.up);
    var hit : RaycastHit;    
    Debug.DrawRay(charp.transform.position, -up * 0.5, Color.green);
         
         
         poshelper2=charp.transform.position;
         forward= transform.TransformDirection(Vector3.forward);
         up= transform.TransformDirection(Vector3.up);
         var controller : CharacterController = GetComponent(CharacterController);
         controller.Move(-(new Vector3(0,1,0)*gravity*Time.deltaTime));
         for (var state : AnimationState in animation) {
         state.speed=3.0;
         
           if(Input.GetKeyDown("space")){
               if(controller.isGrounded){
                 jumpstep=steps;
                 }
                 
             }
             grounded=Physics.Raycast(charp.transform.position, -up, hit, 0.5);
             congrounded=controller.isGrounded;
             diraxis=Input.GetAxis("Horizontal");
          speedaxis=Input.GetAxis("Vertical");
          controller.Move(transform.TransformDirection(Vector3.right)*Speed3*diraxis*Time.deltaTime);
          controller.Move(transform.TransformDirection(Vector3.forward)*Speed3*speedaxis*Time.deltaTime);
          if(speedaxis!=0&&Physics.Raycast(charp.transform.position, -up, hit, 0.5)){
          anim.CrossFade("walk");
          }else{
          state.speed=0.5;
          anim.CrossFade("idle");
          }
   
        
 
         if(jumpstep>0){
             if(jumpstep>10){
             controller.Move(up*jumpspeed*Time.deltaTime);
             jumpstep--;
             }else{
             controller.Move(up*jumpspeed*0.5*Time.deltaTime);
             jumpstep--;
             }
         }
 
 
 }
 poshelper=charp.transform.position;
 }        
 function OnControllerColliderHit (hit : ControllerColliderHit)
 {
     var body : Rigidbody = hit.collider.attachedRigidbody;
     if (body == null || body.isKinematic) { return; }
     if (hit.moveDirection.y < -0.3) { return; }
     var pushDir = Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);
     body.velocity = pushDir * pushPower;
 }



the problem is that i cant figure out when im falling or on the ground, becuase controller.isgrounded dont work, i also tried with raycasts but it also dont work, i tried to debug it by adding two varriables called grounded and congrounded as u can see in the code they are boolean and change in update, but when my character is on the ground non work, the ground var is always off and the raycast thing only trigger randomly when i jump, can you figure out whats going on? thanks.

Comment
Add comment · Show 1
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 Fattie · Aug 30, 2012 at 10:10 AM 0
Share

did you forget to have a collider somewhere? LOO$$anonymous$$ at all the colliders in your scene.

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

8 People are following this question.

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

Related Questions

Raycast2D Only returns true 1 Answer

Send Raycast to ground, place player at Raycast hit? 1 Answer

ground check isnt working...HELP! 2 Answers

Falling then Apply Damage. 0 Answers

XRRayInteractor Offset Ray Direction 0 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