Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 /
  • Help Room /
avatar image
0
Question by xWerner · Nov 15, 2015 at 07:08 PM · rotate objectballrotatearoundbackdegree

Rotate Ball specific number of degrees and back again

Hey,

i want to rotate an object/ball 30 degree to the left side then back to the starting point and then -45 degree do the right side and back again to the starting point. After some seconds this should repead. I have tried this for hours and with different ways for example with "transform.eulerAngles" , "transform.rotation", "rotateAround" and so on but nothing worked fine. The rotation speed should be variable.

I used the searchfunction and edited some of the scripts I found but I could not score a goal with that.

Here are three attempts wich are not working:

 using UnityEngine;
 using System.Collections;
 
 public class bowlerman_rotation_menu : MonoBehaviour {
 
     public float rotation_speed = 10;
     public float target_left_reached;
     public float target_right_reached;
 
 
     bool targetreached_right = true;
     bool targetreached_left = false;
 
 
 
     // Use this for initialization
     void Start () {
         //target_minus_right = this.transform.position + new Vector3(0, target_right, 0);
         //target_plus_left = this.transform.position + new Vector3(0, target_z, 0);
     }
 
     
     void Update(){
 
         if (targetreached_right)
         {
             Target_reached_left();
         }
         if (targetreached_left)
         {
             Target_reached_right();
         }
 
     }
 
     void Target_reached_left()
     {
         target_left_reached += Input.GetAxis("Horizontal");
         transform.eulerAngles = new Vector3(10, target_left_reached, 0);
         //transform.RotateAround(this.transform.position, this.transform.up, rotation_speed * Time.deltaTime);
         if (transform.eulerAngles.y == target_left_reached)
         {
             targetreached_right = false;
             targetreached_left = true;
         }
     }
 
 
     void Target_reached_right()
     {
         target_right_reached += Input.GetAxis("Horizontal");
         transform.eulerAngles = new Vector3(-10, target_right_reached, 0);
         //transform.RotateAround(this.transform.position, this.transform.up, rotation_speed * Time.deltaTime);
         if (transform.eulerAngles.y == target_right_reached)
         {
             targetreached_right = true;
             targetreached_left = false;
         }
     }
 
 }
 



====================================

 using UnityEngine;
 using System.Collections;
 using System;
 
 public class bowlerman_rotate : MonoBehaviour
 {
 
     public float speed = 1.0f;
     public float target_z;
     public float target_minus_z;
     Vector3 target = Vector3.zero;
     Vector3 target_minus = Vector3.zero;
     public float step;
     public float magnitutde;
 
     bool targetreached_right = true;
     bool targetreached_left = false;
 
 
 
 
     void Start()
     {
         target_minus = this.transform.position + new Vector3(0, target_minus_z, 0);
         target = this.transform.position + new Vector3(0, target_z, 0);
     }
 
     void Update()
     {
         step = speed * Time.deltaTime;
 
         if (targetreached_right)
         {
             Targetreached_left();
         }
         if (targetreached_left)
         {
             Targetreached_right();
         }
     }
 
     void Targetreached_right()
     {
         transform.position = Vector3.RotateTowards(transform.position, target_minus, step, magnitutde);
         if (Mathf.Approximately(transform.rotation.y, target.y))
         {
             targetreached_right = true;
             targetreached_left = false;
         }
     }
 
     void Targetreached_left()
     {
         transform.position = Vector3.MoveTowards(transform.position, target_minus, step);
         if (Mathf.Approximately(transform.rotation.y, target_minus.y))
         {
             targetreached_left = true;
             targetreached_right = false;
         }
     }
 
 
 
 }

=======================================

 public class bowlerman_rotate : MonoBehaviour {
 
 
     //public float rotation_speed = 50.0f;
     public float speed = 5.0f;
 
     void Start()
     {
        
     }
 
     // Update is called once per frame
     void Update () {
 
         transform.Rotate(Vector3.up * Time.deltaTime * speed, Space.Self);
 
         //transform.rotation = Quaternion.AngleAxis(47, Vector3.up * Time.deltaTime* slowdown);
 
 
         // transform.rotation = Quaternion.FromToRotation(Vector3.up, transform.(new Vector3(0, 47, 0) * Time.deltaTime));
         //transform.RotateAround(this.transform.position, this.transform.up, rotation_speed * Time.deltaTime);
     }
 }


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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Select next and previous child gameobject on press key 1 Answer

Rotate Around a character World X axis - weird issue 1 Answer

Rotating around another object without parent/child relation?? 0 Answers

Best Method to Rotate Camera around a GameObject while looking at another? 0 Answers

How to replicate Transform.RotateAround error using quaternions? 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