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 Yamin-Nather · Dec 22, 2016 at 08:59 AM · rigidbodymovingautomatically

The rigidbody sphere moves in y axis automatically without adding force in that direction

So i am trying to recreate rolling sky (a mobile game) just as a test to see if i actually learnt anything and not for publishing, as im not getting any idea for my own game.
So now i created some tiles and created a sphere and addded a rigidbody to it and placed it one the tiles.
Then i wrote a code to change the rigidbody.velocity.z to a value of a variable which determines the speed
so now it moves forward continuously, the way it to but then there's a increase in rigidbody.velocity.y which makes it move upward and im not sure why dats happening
So i tried placing the ball in a extended cube instead of tiles and it move only forward (theres no increase in velocity.y)
But if place the ball in the tiles it moves upwards. Gravity brings it down but when the ball has to hit a tile and has to perform some function it just moves up and not touch the tile and completely skips the tile before coming back down automatically by gravity.
If i dont enable the gravity option it just keeps moving up with a fixed velocity which it acquired while it touches the first tile.
I have no clue wat is happening.
Thanks in advance if anyone has a solution to this,
so this is the script attached to the ball

 using UnityEngine;
 using System.Collections;
 
 public class PlayerManager : MonoBehaviour {
 
     public float ZSpeed;
     public float XSpeed;
     Rigidbody rigidbody;
     public float JumpForce;
     public Vector3 Velocity;
 
     void Start () 
     {
         rigidbody = this.gameObject.GetComponent<Rigidbody> ();
     }
     
 
     void Update () 
     {
         ForwardMove ();
         VerticalMove ();
         Velocity = rigidbody.velocity;
 
     }
 
     public void ForwardMove ()
     {
         rigidbody.velocity = new Vector3 (rigidbody.velocity.x, rigidbody.velocity.y, ZSpeed);
     }
 
     public void VerticalMove ()
     {
         float XKey = Input.GetAxis ("Horizontal");
         if (XKey != 0) 
         {
             rigidbody.velocity = new Vector3 (XKey * XSpeed, rigidbody.velocity.y, rigidbody.velocity.z);
         }
         else 
         {
             rigidbody.velocity = new Vector3 (0f, rigidbody.velocity.y, rigidbody.velocity.z);
         }
     }
 
     public void OnTriggerEnter (Collider C)
     {
         if (C.transform.tag == "Destroy")
         {
             GameObject.Destroy (this.gameObject);
             Debug.Log ("Destroy done");
         }
         if (C.transform.tag == "Jump")
         {
             rigidbody.AddForce (0f, JumpForce, 0f);
             Debug.Log ("Jump Done");
         }
     }
 }

At the beginning its like this At the beginning

Then it starts flying
alt text

unity-1.png (144.2 kB)
unity-2.png (192.4 kB)
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

96 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

Related Questions

Moving rigid body objects inside another rigid body object (like a box) 1 Answer

How to make a cube rotate while moving? 1 Answer

Best way to pick up objects in unity? 2 Answers

First Person Controller flying upwards when moving mouse 0 Answers

how to make 3 instances with interchangeable position 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