Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Jonami90 · Nov 21, 2015 at 07:29 PM · rotationmovementcollidersaxis

Move an object by rotation

I'm trying to make a game where you move objects only on the X-axis by rotating them (a 2D-game, though I'm not using Unity2D right now, but I'm not counting it out either). So a ball is simple, the Unity roll-a-ball tutorial was exactly what I needed for that, however it's with other objects that I'm having problems.

A basic cube rolls without that many problems, however I've also got a cross-shaped object and a triangle-shaped object that I'd like to be able to move. With the cross shaped object, the longer I make it move the more it starts slowing down and "fighting back", when I release the key it jumps backwards and then settles down. The triangle is even less responsive, as it has serious problems even getting moving. Also, even though I've set them to freeze their Z-axis rotation and movement when I move them, they still move ever so slightly on the Z-axis, eventually falling off the level.

Here's the code I'm using for moving the cross, the other objects follow the same principle (except the ball, that's almost entirely the same as the roll-a-ball).

 using UnityEngine;
 using System.Collections;
 
 public class MoveCross : MonoBehaviour
 {
     public float degrees;
     private Rigidbody rotateObject;
     public float speedRot = 10.0f;
     public Transform moveObject;
     public float speedMove = 6.0f;
 
     // Use this for initialization
     void Start()
     {
         rotateObject = GetComponent<Rigidbody>();
         moveObject = GetComponent<Transform>();
     }
 
     // Update is called once per frame
     void Update()
     {
         Vector3 transform = Vector3.zero;
         transform.x = Input.GetAxis("Horizontal");
         transform.z = 0;
         transform = transform * speedMove * Time.deltaTime;
         moveObject.position += transform;
 
         if (Input.GetKey("left"))
         {
             rotateObject.transform.Rotate(Vector3.up, degrees * speedRot * Time.deltaTime);
 
             rotateObject.constraints = RigidbodyConstraints.FreezePositionZ;
             rotateObject.constraints = RigidbodyConstraints.FreezeRotationZ;
             //break;
         }
 
         if (Input.GetKeyUp("left"))
         {
             rotateObject.constraints = RigidbodyConstraints.None;
         }
 
         if (Input.GetKey("right"))
         {
             rotateObject.transform.Rotate(Vector3.up, degrees * (-1) * speedRot * Time.deltaTime);
 
             rotateObject.constraints = RigidbodyConstraints.FreezePositionZ;
             rotateObject.constraints = RigidbodyConstraints.FreezeRotationZ;
             //break;
        }
 
         if (Input.GetKeyUp("right"))
         {
             rotateObject.constraints = RigidbodyConstraints.None;
         }
     }
 }

So I need to stop the object from moving any way on the Z-axis so that they won't drop off the level or fall over and I also need to find out what is hindering the movement of the cross and triangle objects. For the Cross, I tried both with a Mesh collider and with two Box colliders that I edited to fit the cross, the triangle had a Mesh collider. Thanks in advance!

Comment
Add comment · Show 1
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 Jonami90 · Nov 21, 2015 at 07:29 PM 0
Share

Quick edit, seems like with the cross increasing the rotation angle at least helps with the object "fighting back", however the Z-axis is still a bother.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Creating own "x" and "z" axis to move player along? 0 Answers

How could I rotate an object relative to its movement on an axis? 0 Answers

how do i reference two input axis at one time on javascript 0 Answers

How to rotate fluently/smoothly? 1 Answer

Rotate Object Axis On Swipe Cam Rotation - Android 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