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 Paul Ash · Nov 24, 2010 at 04:44 AM · physicsgravityplanetsmariofauxgravity

Faux Gravity, spinning at bottom of sphere

I'm working on a faux style gravity simulation (like mario galaxy) I have it working about 90% but when the player is running around the sphere, after a few rotations they become locked into spinning at the bottom of the sphere I'm completely out of ideas on how to deal with this so any input would be greatly helpful

</p> <pre><code>public float MoveSpeed = 20.0f; public float TurnSpeed = 10.0f; private Vector3 playerGravity = new Vector3(0, -3, 0); private Animation ani; private CharacterController controller; private float Angle = 0.0f; private Quaternion quat = Quaternion.identity; // Use this for initialization void Start () { ani = transform.FindChild("body").animation; controller = transform.GetComponent("CharacterController") as CharacterController; } void UpdateFloorRotation() { GameObject floor = GameObject.FindGameObjectWithTag("Level"); Vector3 floorVec = -transform.position.normalized; playerGravity = floorVec * 0.1f; RaycastHit hitInfo; if (Physics.Raycast(transform.position, floorVec, out hitInfo, 10, 1 &lt;&lt; 8)) { Debug.Log("Floor: " + hitInfo.collider.name); transform.rotation = quat * Quaternion.FromToRotation (Vector3.up, transform.position.normalized); Debug.Log("Normal: " + floorVec); } } // Update is called once per frame void Update () { Vector3 Locomotion = Vector3.zero; Vector2 gravity = Physics.gravity; Physics.gravity = playerGravity; if (Input.GetButtonDown("Jump")) { if (ani != null) { //ani.CrossFade("use"); } } if (Input.GetButtonUp("Up") || Input.GetButtonUp("Down") || Input.GetButtonUp("Left") || Input.GetButtonUp("Right")) { if (ani != null) { ani.CrossFade("idle"); } } if (Input.GetButton("Up")) { Locomotion += (-transform.forward * MoveSpeed); if (ani != null) { ani.CrossFade("run"); } } if (Input.GetButton("Down")) { Locomotion += (transform.forward * MoveSpeed); if (ani != null) { ani["walk"].speed = -1; ani.CrossFade("walk"); } } if (Input.GetButton("Left")) { Angle += -TurnSpeed * 1; if (ani != null &amp;&amp; !Input.GetButton("Up")) { ani["walk"].speed = 1; ani.CrossFade("walk"); } } if (Input.GetButton("Right")) { Angle += TurnSpeed * 1; if (ani != null &amp;&amp; !Input.GetButton("Up")) { ani["walk"].speed = 1; ani.CrossFade("walk"); } } Locomotion *= Time.deltaTime; quat = Quaternion.AngleAxis(Angle, playerGravity.normalized); Vector3 targetDir = transform.TransformDirection(Vector3.down); if (!Physics.Raycast(transform.position, targetDir, 3.3f, 1 &lt;&lt; 8)) { Debug.Log("Falling!"); Locomotion += playerGravity; } controller.Move(Locomotion); UpdateFloorRotation(); } </code></pre> <p>

Comment
Add comment · Show 4
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 Paul Ash · Nov 24, 2010 at 05:08 AM 0
Share

really frustrating because it seems very random, sometimes i can run around the planet 20 times before it happens, others it happens right away, maybe time depended?

avatar image Paul Ash · Nov 24, 2010 at 06:06 AM 0
Share

Guess it was time related, I changed Update to FixedUpdate and most of the problems went away, now it only does the crazy spinning at the bottom of the sphere when the player has tried to spin there character (Pressed left or right) then it goes hang wire pretty fast.

avatar image Paul Ash · Nov 24, 2010 at 09:42 AM 0
Share

I figured it out, quat needed to be calculated with Vector3.up, like the rotation in the updateRotation method, then it needs to be the second component multiplied together.

avatar image Paul Ash · Nov 24, 2010 at 09:57 AM 0
Share

ack, I take that back, its very close now, but now anytime the player is walking around the surface its always moving slightly towards the bottom of the sphere.

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

No one has followed this question yet.

Related Questions

Mario Galaxy -ish controls problem 1 Answer

Unity3D PlanetGravity system? C# 1 Answer

Character Controller and Camera for Faux gravity..(Mario Galaxy) 3 Answers

Multiple Planets with their own gravitational pull 1 Answer

Applying Normal force from ground to player 1 Answer


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