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

avatar image omaramradelmohamed12345 logicandchaos · May 22, 2021 at 06:57 AM 0
Share

didn't work maybe I didn't write it in a proper way but its not working

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

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

How to make that the camera will not go through the walls? 1 Answer

CCTV behavior rotation issue 2 Answers

if the fps is high the camera rotate much faster 1 Answer

How can i place subjects in different positions? 0 Answers

Arm Rotation toward Cursor Script Help 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