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 /
  • Help Room /
avatar image
0
Question by ThatGuyBrian · May 09, 2016 at 04:53 AM · c#rigidbodygravityinheritance

GravityBody hides Rigidbody

Hello! I'm a tad new to Unity, and even newer to C#. I've been using Sebastian League's planetary gravity system to build a mini-game for fun. However, I've recently added in a new character model, and I've been getting the following error.

Assets/GravityBody.cs(8,19):warning CS0108: 'GravityBody.rigidbody' hides inherited member 'UnityEngine.Component.rigidbody'. Use the new keyword if hiding was intended.

Now, I'm well aware there are a few other topics related to this issue. But I'm assuming the answers for all of them don't really apply to this situation. I'd love to get some help here... By the way, here's some code.

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent (typeof (Rigidbody))]
 public class GravityBody : MonoBehaviour {
     
     GravityAttractor planet;
     Rigidbody rigidbody;
     
     void Awake () {
         planet = GameObject.FindGameObjectWithTag("Planet").GetComponent<GravityAttractor>();
         rigidbody = GetComponent<Rigidbody> ();
 
         // Disable rigidbody gravity and rotation as this is simulated in GravityAttractor script
         rigidbody.useGravity = false;
         rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
     }
     
     void FixedUpdate () {
         // Allow this body to be influenced by planet's gravity
         planet.Attract(rigidbody);
     }
 }

Comment
Add comment · Show 2
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 ThatGuyBrian · May 10, 2016 at 08:32 AM 0
Share

Bumpity bump bump...

avatar image ThatGuyBrian · May 11, 2016 at 01:12 AM 0
Share

Buuuuuuuuuuuuuuuuuuuuuuuuuump.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by M-Hanssen · May 10, 2016 at 09:16 AM

You cannot name your Rigidbody "rigidbody" because it hides the legacy "rigidbody" variable name.

Think of another name like "gravityRigidbody" ;-)

Or do the following to the variable declaration:

 private new Rigidbody rigidbody;
Comment
Add comment · Show 2 · 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 ThatGuyBrian · May 10, 2016 at 07:52 PM 0
Share

Also, I do have one more issue, it's with the first person controller script. The console appears to be giving me this issue.

Assets/FirstPersonController.cs(20,19): warning CS0108: FirstPersonController.rigidbody' hides inherited member UnityEngine.Component.rigidbody'. Use the new keyword if hiding was intended.

Here's the code. using UnityEngine; using System.Collections; [RequireComponent (typeof (GravityBody))] public class FirstPersonController : $$anonymous$$onoBehaviour { // public vars public float mouseSensitivityX = 1; public float mouseSensitivityY = 1; public float walkSpeed = 6; public float jumpForce = 220; public Layer$$anonymous$$ask grounded$$anonymous$$ask; %|-367189528_8|% // System vars bool grounded; Vector3 moveAmount; Vector3 smooth$$anonymous$$oveVelocity; %|260141021_13|% Transform cameraTransform; Rigidbody rigidbody; void Awake() { Cursor.lockState = CursorLock$$anonymous$$ode.Locked; Cursor.visible = false; %|1409941851_21|% rigidbody = GetComponent<Rigidbody> (); } %|-1972943753_24|% void Update() { // Look rotation: transform.Rotate(Vector3.up * Input.GetAxis("$$anonymous$$ouse X") * mouseSensitivityX); verticalLookRotation += Input.GetAxis("$$anonymous$$ouse Y") * mouseSensitivityY; verticalLookRotation = $$anonymous$$athf.Clamp(verticalLookRotation,-60,60); cameraTransform.localEulerAngles = Vector3.left * verticalLookRotation; // Calculate movement: float inputX = Input.GetAxisRaw("Horizontal"); float inputY = Input.GetAxisRaw("Vertical"); Vector3 moveDir = new Vector3(inputX,0, inputY).normalized; %|-691205467_38|% moveAmount = Vector3.SmoothDamp(moveAmount,target$$anonymous$$oveAmount,ref smooth$$anonymous$$oveVelocity,.15f); // Jump if (Input.GetButtonDown("Jump")) { if (grounded) { rigidbody.AddForce(transform.up * jumpForce); } } // Grounded check Ray ray = new Ray(transform.position, -transform.up); RaycastHit hit; if (Physics.Raycast(ray, out hit, 1 + .1f, grounded$$anonymous$$ask)) { grounded = true; } else { grounded = false; %|-1143165390_57|% } void FixedUpdate() { %|-654216127_62|% Vector3 local$$anonymous$$ove = transform.TransformDirection(moveAmount) * Time.fixedDeltaTime; rigidbody.$$anonymous$$ovePosition(rigidbody.position + local$$anonymous$$ove); } }

avatar image M-Hanssen ThatGuyBrian · May 11, 2016 at 09:27 AM 0
Share

What the hell dude!? What part of my answer don't you understand??? The solution to this problem is exactly the same...

Change Rigidbody rigidbody; to private new Rigidbody rigidbody;

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

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

Related Questions

Gravity is not working 0 Answers

Change player gravity by pressing a key? 1 Answer

I added Rigidbody to my cube and now it goes super fast when i move! 0 Answers

Adding Gravity to a game object to make a black hole sucking effect. 1 Answer

Faux Gravity Character Rotate Problem 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