Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Dancetrap · Nov 11, 2021 at 01:46 AM · rotationplayer movementcontrolsupside-down

Player Controls Upside Down

 public class Gravity : MonoBehaviour
 {
     private float g = -9.81f;
     private bool gravity = true;
     Character player;
     GameObject avatar;
     // Start is called before the first frame update
     void Start()
     {
         player = GameObject.FindGameObjectWithTag("Player").GetComponent<Character>(); 
         avatar = GameObject.Find("Rainboy");
     }
 
     // Update is called once per frame
     void Update()
     {
         Physics.gravity = new Vector3(0, g, 0);
         if(Input.GetKeyDown(KeyCode.G)){
             if(gravity)
             {
                 gravity = false;
                 print(Physics.gravity);
             }
             else if(!gravity)
             {
                 gravity = true;
                 print(Physics.gravity);
             }
         }
 
         print(g);
 
 
         if(!gravity)
         {
             g = 9.81f;
             player.gravity = false;
             //player.chara.position.y += 1.5f;
             //pos.y = 1.5f;
             //Physics.gravity = new Vector3(0, 9.81f, 0);
         }
         else if(gravity)
         {
             //player.rig.velocity = new Vector3(player.x,player.rig.velocity.y,player.z);
             player.gravity = true;
             g = -9.81f;
             //Physics.gravity = new Vector3(0, -9.81f, 0);
         }
     }
 
     void OnTriggerEnter(Collider other)
     {
         Physics.gravity = new Vector3(0, g, 0);
         if(gravity){
             gravity = false;
         }
 
         else{
             gravity = true;
         }
     }
 
 public class Character : MonoBehaviour
 {
    [HideInInspector]
     public float x;
     [HideInInspector]
     public float y;
     [HideInInspector]
     public float z;
 private bool dead = false;
 private float angle = 0;
 void Update()
     {
         if(!dead){
         x = Input.GetAxis("Horizontal") * moveSpeed;
 
         z = Input.GetAxis("Vertical") * moveSpeed;
 
         y = Input.GetAxis("Jump") * moveSpeed;
 
         }
 
         if(!dead)
         {
             rig.velocity = new Vector3(x,rig.velocity.y,z);
         }
         else
         {
             rig.velocity = new Vector3(0,0,0);
         }
         
         Vector3 vel = rig.velocity;
         vel.y = 0;
 
         if(vel.x != 0 || vel.z != 0){
             transform.forward = vel;
         }    
 
         if(gravity)
         {
             StartCoroutine(GDelay());
         }
         else if(!gravity)
         {
             StartCoroutine(ZeroGDelay());
         }
     
 if(jump == true){
     if(Input.GetKeyDown(KeyCode.Space) && isGrounded == true){ 
         isGrounded = false;
         if(gravity){
             rig.AddForce(Vector3.up * jumpForce, ForceMode.Impulse); 
         }
         else if(!gravity)
         {
             rig.AddForce(Vector3.down * jumpForce, ForceMode.Impulse); 
         }
         //AudioListener.volume = 1.0f;
         if(on == true){
             jumpSound.mute = false; 
             jumpSound.Play();
         }
      }
 }
 }
 
 public IEnumerator ZeroGDelay(){
     yield return new WaitForSeconds(0.5f);
     angle = 180;
 }
 
 public IEnumerator GDelay(){
     yield return new WaitForSeconds(0.5f);
     angle = 0;
 }
 
 }

The rest is pretty self-explanatory. I want to be my character walk around upside down, but everytime they move it flips them right-side up

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 Captain_Pineapple · Nov 11, 2021 at 01:38 PM 0
Share

sorry but no this is not "self-explanatory" imo. you post 150 lines of code and a half a sentence describing your problem... What does not work? What have you tried?


as a rule of thumb: if you post more than 50 lines of code you should break the issue further down. If you are not able to do that how should others know what to do?

avatar image Dancetrap Captain_Pineapple · Nov 11, 2021 at 01:46 PM 0
Share

Ok, here's the basics. So when my character changes gravity, I program it so that he will flip 180 degrees on the "z" rotation. But whenever he moves while upside down, his "z" rotation reverts back to 0, making him collide with the platform and eventually going of the platform and flying off. I realized that the problem lied in Line 96, so I created a bool for that, and he does move upside down, but that just brings up another problem with him not flipping back to 0 degrees on the "z" axis. I also made the character jump down while he's upside down, but whenever he reverts back to normal gravity, he still jumps down, even though I created a bool to tell him otherwise.

I hope this is understandable for you

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

180 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 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 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

Rotate player in movement direction 1 Answer

How to have a scene rotate with the device orientation 0 Answers

Player Movement & Blend Tree - Can anyone help with my script? 1 Answer

Controls stop working on computer when hooked up to Unity Remote 0 Answers

aiming up and down 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