• 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
1
Question by omaramradelmohamed12345 · May 20, 2021 at 02:49 PM · rotationscripting problemballendless runner

How to make the ball rotate

I have an endless runner game that the ball keeps moving forward and the player can move it only right and left but the problem is the ball move forward without rotating I tried "transform.Rotate(r,0,0);" when "r" is variable that keeps rotating and accelerates but the object rotates around another point not its axis. (the function move() is the one responsible for moving it forward) of corse I don't use gravity


using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;

public class mover : MonoBehaviour { [SerializeField] float moveSpeed = 10f; [SerializeField] float delay = 5f; [SerializeField] float movingSpeed= 1f; [SerializeField] float speedAcceleration = 0.0001f; private Touch touch; private float touchSpeed = 0.02f; public static bool gameStarted = false;

 public static bool dead = false;

 [SerializeField] public static float timer = 0.0f;

 public GameObject diePanel;

 // Start is called before the first frame update
 void Start()
 {

 }

 // Update is called once per frame
 void Update()
 {
       timerCount();
       if ( SwipeManager.swipeLeft||SwipeManager.swipeRight ||SwipeManager.swipeUp ||SwipeManager.swipeDown|| Input.GetKeyDown("w"))
       {
          gameStarted = true;
       }
       move();
       Movetouch();
 }

 private void OnCollisionEnter(Collision other) 
 {
    if(other.gameObject.tag == "obestcle")
    {
       gameStarted = false;
       dead = true;
       diePanelopen();
      //Invoke("tryagain",delay);
    }     

}

 void move(){
     if (dead == false && gameStarted == true )
     {
         movingSpeed = movingSpeed + speedAcceleration;
         float x = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed  ;
         float z = Time.deltaTime * moveSpeed * movingSpeed ;
         transform.Translate(x,0,z);
     }

 }

 void Movetouch()
 {
     if (Input.touchCount > 0 )
     {                     
         touch = Input.GetTouch(0);

        if (touch.phase == TouchPhase.Moved && dead == false && gameStarted == true)
        {

            if (transform.position.x + touch.deltaPosition.x * touchSpeed > 9)
            {
                  transform.position = new Vector3( 9, transform.position.y,transform.position.z);
            }
            else if (transform.position.x + touch.deltaPosition.x * touchSpeed < -8  )
             {
                transform.position = new Vector3(-8, transform.position.y,transform.position.z);
             }
             else
             {
                transform.position = new Vector3(transform.position.x + touch.deltaPosition.x * touchSpeed , transform.position.y,transform.position.z);
             }
        } 
     }
 }
 void tryagain()
 {
    dead = true;
    gameStarted = false;
    diePanelopen();

 }
 void timerCount()
 {
    if (gameStarted == true)
    {
       timer += Time.deltaTime;
    }
 }
 void diePanelopen()
 {
     if(diePanel != null)
     {
         bool isActive = diePanel.activeSelf;
         diePanel.SetActive(!isActive);
         mover.gameStarted = false;

     }
     else if (Restart.isPanelOffOnRestart == true)
     {
       diePanel.SetActive(false);
       Restart.isPanelOffOnRestart = false;
     }
 }

}

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 logicandchaos · May 20, 2021 at 04:45 PM 0
Share

try angualrVelocity.

Show more comments

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

244 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Ball Get Stuck on Rotating Platform 1 Answer

FPS Controller rotation,FPS Controller rotation problem 0 Answers

Tiles spawn slightly to the right of my player 1 Answer

Rotation drift with transform.eulerAngles 0 Answers

Inheriting Parent Rotation and position 2 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