- Home /
Anti-Gravity isn't working
Hello! I am new to using Unity and I'm hoping for a hint about where the problem may be in my code that is preventing my gravity to inverse from being applied every time I hit the button to "flip" my character (rotate the char upside down to walk on the ceiling or floor)
  if (Input.GetKeyDown(KeyCode.G))
         {
             if (isFlipped == false)
             {
                 if (player.isGrounded)
                 {
                     transform.position = transform.position + Vector3.up * 2;
                 }
                 Debug.Log("Attempting to Flip");
                 currentAngle = transform.eulerAngles;
 
                 //lock controls until flipping completes : not yet made (don't worry about it)
 
                 Vector3 rot = transform.rotation.eulerAngles;
                 rot = new Vector3(rot.x, rot.y, rot.z + 180);
                 transform.rotation = Quaternion.Euler(rot);
 
                 isFlipped = true;
             }
             else
             {
                 Debug.Log("Attempting to Flip");
 
 
                 //lock controls until flipping completes
 
                 Vector3 rot = transform.rotation.eulerAngles;
                 rot = new Vector3(rot.x, rot.y, rot.z - 180);
                 transform.rotation = Quaternion.Euler(rot);
 
                  isFlipped = false;
              }
 
          }
 
 
 //jumping
          if (isFlipped == false)
          {
              if (player.isGrounded)
              {
                  vSpeed = 0;
                  if (Input.GetKeyDown(KeyCode.Space))
                  {
                      vSpeed = jumpHeight;
                  }
              }
              //gravity
              vSpeed -= gravity * Time.deltaTime;
              movement.y = vSpeed;
 
          }
          else
          {
              gravity = gravity * -1;
 
              if (player.isGrounded)
              {
                  vSpeed = 0;
                  if (Input.GetKeyDown(KeyCode.Space))
                  {
                      vSpeed = jumpHeight * -1;
                  }
              }
              //gravity
              vSpeed += gravity * Time.deltaTime;
              movement.y = vSpeed;
          }
 
 
          movement = transform.rotation * movement;
          player.Move(movement * Time.deltaTime);
 
Answer by Saiguru · Mar 14, 2019 at 06:21 AM
Hi @Collywog , Pls check this video https://www.youtube.com/watch?v=hX70SNM_XWI It's in 2D, but I guess you can make use of that as a reference
Unfortunately this video doesn't quite show me what I need it to because I'm using a character controller and my own gravity, thank you for the reply though!
Your answer
 
 
             Follow this Question
Related Questions
Jumping a specific height using Velocity & Gravity 1 Answer
Adding force to the charactercontroller for walljump 1 Answer
unity 5 game 2.5 trouble jumping 2 Answers
Player Character looses jump height the further right they go 1 Answer
How would I get my character to be able to move while in the air after a jump? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                