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 Tekksin · Oct 25, 2013 at 09:43 PM · rigidbodyraycastheightrigidbody-collisionrigidbody physics

'height' is not a member of 'UnityEngine.Collider'.

I'm desperately fighting for some answers here.

ignoring the stuff thats been disabled, what am I doing wrong here? And why doesn't unity recognise height? Information taken from this tutorial: http://www.packtpub.com/article/unity-3.x-rigidbody-character-controller-script

the "height" problem is found under "fixed update". Please hlep, thanks. I have no idea what's happening.

 #pragma strict
 
 var health : int = 100;
 //var speed : int = 5;
 //var jumpSpeed: float = 8;
 //var isgrounded : boolean = true;
 
 public var jumpSpeed : float = 500.0;
 public var jumpDirection : Vector3 = Vector3.zero;
 public var isGrounded : boolean = false;
 public var Jumping : boolean = false;
 public var inAir : boolean = false;
 public var airControl : float = 0.5;
 public var MoveDirection : Vector3 = Vector3.zero;
 public var Speed : float = 5.0;
 
 function Start () {
 
 }
 
 
 function Update () {
 
 
 //    if(isgrounded == true){
 //        if (Input.GetKeyDown (KeyCode.Space)){
 //        rigidbody.velocity += Vector3.up * jumpSpeed;
 //        Physics.gravity = Vector3(0,-50,0);
 //        }
 //}
 
 
 
 
 //    if(Input.GetAxis("Horizontal")){
 //        transform.Translate(Vector3(Input.GetAxis("Horizontal") * speed * Time.deltaTime, 0, 0));
 //    }
     
     var AT = gameObject.GetComponent(AnimateTexture); //Store AnimateTexture Script
     if(Input.GetKey("a")){ //Player moves left
         AT.rowNumber = 1; //Change to running animation
     } else if(Input.GetKey("d")){ //Player moves right
         AT.rowNumber = 1; //Change to running animation
     } else { //Player is not moving
         AT.rowNumber = 0; //Change to idle animation!
     }
     if(Input.GetKey("space")){
         AT.rowNumber = 3; //Player jumping animation
     }
     if(Input.GetKey("up")){
         AT.rowNumber = 3; //Player jumping animation
     }
     if(Input.GetKey("s")){
         AT.rowNumber = 4; //Player squats down
     }
     if(Input.GetKey("left")){
         AT.rowNumber = 1;
     }
     if(Input.GetKey("right")){
         AT.rowNumber = 1;
     }
     if(Input.GetKey("down")){
         AT.rowNumber = 4;
     }   
 }
 
 //    function OnCollisionEnter(theCollision : Collision){
 //if(theCollision.gameObject.name == "floor"){
 //        isgrounded = true;
 //    }
 //}
 
 //    function OnCollisionExit(theCollision : Collision){
 //    if(theCollision.gameObject.name == "floor"){
 //        isgrounded = false;
 //    }
 //}
 
 
 
 
 function FixedUpdate (){
     if (!isGrounded){
         if (Physics.Raycast(transform.position, -transform.up, collider.height/2 + 0.2)){
             isGrounded = true;
             Jumping = false;
             inAir = false;
          }
         else if (!inAir){
             inAir = true;
             jumpDirection = MoveDirection;
          } 
      }  
 Movement();
 }
 function OnCollisionExit(collisionInfo : Collision){
     isGrounded = false;
 }
 
 
 
 
 function Movement(){
     if (Input.GetAxis("Horizontal") || Input.GetAxis("Vertical")) {
     MoveDirection = Vector3(Input.GetAxisRaw("Horizontal"),
     MoveDirection.y,Input.GetAxisRaw("Vertical"));
     }
     if (Input.GetKeyDown("space") && isGrounded){
     
         if (Input.GetButtonDown("Jump") &&isGrounded){
             Jumping = true;    
             jumpDirection = MoveDirection;
             rigidbody.AddForce((transform.up) * jumpSpeed);
     
         }
     if (isGrounded)
         this.transform.Translate((MoveDirection.normalized * Speed) * 
         Time.deltaTime);
         else if (Jumping || inAir)
         this.transform.Translate((jumpDirection * Speed * airControl) * 
         Time.deltaTime);
 
 
     }
 } 
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

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by rutter · Oct 25, 2013 at 09:54 PM

The tutorial was probably relying on dynamic typing. It's a powerful language feature, but it's not supported on mobile and is disabled when you're using #pragma strict.

(Side note: I'm of the opinion that you should always use strict. You can code faster without it, sometimes, but it's really easy to miss problems like this one.)

Some colliders, such as CapsuleCollider, do have a height attribute. The reference returned by collider doesn't know which type of collider is attached, though, so it returns the most general type it can: Collider.

If you know for sure that it's a capsule collider, you could cast the reference:

 ((CapsuleCollider)collider).height

As an alternative, every collider also has a bounds attribute you could use:

 collider.bounds.size.y
Comment
Add comment · Show 4 · Share
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 Tekksin · Oct 25, 2013 at 10:00 PM 0
Share

I'm using a regular box collider, because I'm making a 2d game. During platfor$$anonymous$$g parts, the character can gradually slope off because of the capsule collider, so I switched from a character controller to a rigid body, and now i'm having an infinite number of problems lol.

Anyways, it's a basic cube with a 32bit alpha texture on it, and the collider is a box. What do I do to fix the code?

I tried:

 if (Physics.Raycast(transform.position, -transform.up, ((BoxCollider)collider).height/2 + 0.2)){

but that didn't work. I also tried:

 if (Physics.Raycast(transform.position, -transform.up, collider.bounds.size.y.height/2 + 0.2)){

but then I get the error "'height' is not a member of 'float'." :(

avatar image SilentSin · Oct 25, 2013 at 10:01 PM 0
Share

This is the answer you want. I'd recommend type casting over using bounds, but whatever works.

avatar image Tekksin · Oct 25, 2013 at 10:03 PM 0
Share

what is an example code of what you recommend? Please take into account my response above yours. Thanks for the help guys..

avatar image Tekksin · Oct 25, 2013 at 10:04 PM 0
Share

The character is also not moving, with this code/tutorial... sigh.. lol...

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

18 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

Related Questions

Wall jump, jump movement not working 0 Answers

How to limit only the Rigidbody.velocity from player input? 1 Answer

Rigidbody NavMeshAgent Causing Crazy Collisions with Player. 0 Answers

Problem with Rigidbody control script! (collision with perpendicular walls problem) 1 Answer

2.5D Shooting Rigidbodies vs RayCasts 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