Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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 ergncyln2127088 · May 28, 2021 at 10:01 AM · rotationmovementunity 2drigidbody2dphysics2d

In unity 2D c# how to rotate an object like geometry dash?

I'm newbie here, but will try to describe as clear as I can. At my game my main character is cube and if press space its jumping dependig on how much you press the button but i want to rotate my cube 90 degrees when pressing the space button but im working about this for 10 hours but i couldn't achieve how to do that can anyone help me. Thank you

[Game Video][1]

This is my code :

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlayerEverything : MonoBehaviour{
 
     public Transform GroundCheck; // Put the prefab of the ground here
     
     public LayerMask groundLayerBlue; // Insert the layer here.
     public LayerMask groundLayerPurple;
     public bool isGroundedBlue;   
     public bool isGroundedPurple;
     private Rigidbody2D rb2D;
     private float jumpTimer;
     private float timeCount = 0.0f;
     private bool isGrounded;
     public Transform groundCheck;
     public LayerMask groundLayer;
 
     public float time;
 
     
     
 
     // Start is called before the first frame update
     public void Start()
     {
         rb2D = GetComponent<Rigidbody2D>();
         
 
     }
 
     // Update is called once per frame
     public void Update()
     {
         
         isGroundedBlue = Physics2D.OverlapCircle(GroundCheck.position, 0.15f, groundLayerBlue);
         if (isGroundedBlue)
         {
             transform.position += Vector3.right/60;
         }
         
     
         isGroundedPurple = Physics2D.OverlapCircle(GroundCheck.position, 0.15f, groundLayerPurple);
         if (isGroundedPurple)
         {
             transform.position += Vector3.left / 60;
         }
 
         if (isGrounded)
         {
 
 
             if (Input.GetKey(KeyCode.Space))
             {
                 jumpTimer += Time.deltaTime;
                
                
             }
             if (Input.GetKeyUp(KeyCode.Space))
             {
                 DoJump(350f * jumpTimer);
                 jumpTimer = 0;
 
             }
 
             
         }
         if (Input.GetKeyUp(KeyCode.Space))
         {
             StartCoroutine(Rotate());
 
         }
 
 
     }
     private void FixedUpdate()
     {
         isGrounded = Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer);
     }
 
 
     public void DoJump(float JumpForce)
     {
         float jumpForceMagnitutde = Mathf.Clamp(JumpForce/3, 0, 50);
         rb2D.AddForce(Vector2.up * jumpForceMagnitutde/3, ForceMode2D.Impulse);
         rb2D.AddForce(Vector2.right*jumpForceMagnitutde/10,ForceMode2D.Impulse);
 
     }
     IEnumerator Rotate()
     {
         Quaternion startRotation = transform.rotation;
         
 
         transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(0, 0, 90), 1);
         yield return null;
     }
 
 }
 

Comment
Add comment
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

· Add your reply
  • Sort: 
avatar image
0

Answer by mevsvader · May 28, 2021 at 04:48 PM

didnt read ur code but rotatetowards and rotatearound should help. check for jump input, then select direction and rotate Z - or + 90 in the direction u want.

Comment
Add comment · 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

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

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

Issues with Character Controller moving Enemies 1 Answer

Why does poligon collider 2d restricts movement of box collider? 0 Answers

How to limit rotation angle on a rigidbody2d ? 0 Answers

How to give player a "dash" ability? 0 Answers

how to stop rotation from being uncontrollable 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