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 /
This question was closed Apr 05, 2017 at 07:27 PM by Bunny83 for the following reason:

The question is answered, right answer was accepted

avatar image
2
Question by fabianzaf · Aug 29, 2012 at 08:21 PM · physicsrigidbodycharactercenterofmass

Is there a way to draw center of mass on the screen?

Hi everyone,

I'm trying to see where the center of mass is located on my rigidbody, is there a way to draw it on the screen so I can then position it accordingly?

Thanks in advance!

Comment
Comments Locked
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

  • Sort: 
avatar image
7
Best Answer

Answer by ScroodgeM · Aug 29, 2012 at 09:32 PM

http://docs.unity3d.com/Documentation/ScriptReference/Editor.html

RigidbodyEditor.cs

using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(Rigidbody))]
public class RigidbodyEditor : Editor
{
	void OnSceneGUI()
	{
		Rigidbody rb = target as Rigidbody;
		Handles.color = Color.red;
		Handles.SphereCap(1, rb.transform.TransformPoint(rb.centerOfMass), rb.rotation, 1f);
	}
	public override void OnInspectorGUI()
	{
		GUI.skin = EditorGUIUtility.GetBuiltinSkin(UnityEditor.EditorSkin.Inspector);
		DrawDefaultInspector();
	}
}
Comment
Comments Locked · Show 8 · 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 fabianzaf · Aug 30, 2012 at 01:57 AM 0
Share

Thanks for taking the time to write this! When I add it to Assets/Editor I get

"Instance of RigidbodyEditor couldn't be created because there is no script with that name."

avatar image fabianzaf · Aug 30, 2012 at 02:27 AM 0
Share

Oh never$$anonymous$$d I missed a case letter, playing with your code further now - will get back to you :)

avatar image fabianzaf · Aug 30, 2012 at 03:30 AM 0
Share

Thanks so much this worked perfectly, for anyone that is interested in the Javascript version

@CustomEditor(typeof(Rigidbody)) public class RigidBodyEditor extends Editor { function OnSceneGUI() : void { var rb : Rigidbody = target as Rigidbody; Handles.color = Color.red; Handles.SphereCap(1, rb.transform.TransformPoint(rb.centerOf$$anonymous$$ass), rb.rotation, 0.1f); } override function OnInspectorGUI(): void { GUI.skin = EditorGUIUtility.GetBuiltinSkin(UnityEditor.EditorSkin.Inspector); DrawDefaultInspector(); } }

Note: you have to click on the Gameobject to see the Handle.

Thanks again!

avatar image aybeone · Jul 28, 2015 at 03:19 PM 0
Share

It does work great but there's a side-effect (Unity 5) : the 'Constraints' section of the Rigidbody in the Inspector disappears. Any ideas on how to make it visible again ? Thanks !

avatar image SevenDays aybeone · Oct 23, 2015 at 12:18 PM 0
Share

try to call base.OnInspectorGUI ();

avatar image pixxelbob SevenDays · Dec 10, 2015 at 02:55 PM 0
Share

This duplicates all the other fields but does not bring back the Constraints

avatar image zenforhire · Apr 05, 2017 at 04:17 PM 0
Share

Thanks alot for this script!

avatar image Bunny83 zenforhire · Apr 05, 2017 at 07:26 PM 0
Share

Ins$$anonymous$$d of posting a "thank you" comment of a 4+ years old answer (which bumps the question for no reason) you should simply upvote the answer (and question). That's enough. I'm going to lock the comments to prevent further comment of this kind.

Follow this Question

Answers Answers and Comments

12 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

Related Questions

Character Controller children of a car: Inertia effect, delay effect, what??? 1 Answer

Character controller jittering up and down 2 Answers

Problem with Rigidbody.CenterOfMass 2 Answers

How can I rotate around with a Rigidbody while respecting physics? 0 Answers

AddRelativeTorque() Applied Incorrectly When Using a Custom Centre of Gravity 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