Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by thorapan · Jul 27, 2021 at 07:02 AM · physics3dgravity

3D cube bounces when dropped from a height. How can I stop that?

Hi, I am new to the Unity engine. I was trying to recreate a tower builder game in 3D. The cube moves left and right in the game, and when the player hits space, it drops the cube. Currently, if I stopped the left and right movement and I am just dropping the cube.

The game video link

In the above link, a video of the game is available. Every time I drop a cube, the cube bounces and the structure moves. The structure loses its stability and falls. Is there any way to drop the cube without the bounce? Or is there any way to balance the structure(Maybe stopping the movement in Z-axis without affecting other axes)?

I tried freezing the position along the z-axis. When I do that, the cube starts to slide along the x-axis and the structure falls

This is the tutorial that I am currently following: Tutorial Link

Cube Rigid Body Properties: alt text

Code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 
 [RequireComponent(typeof(Rigidbody))]
 public class MoveCube : MonoBehaviour
 {
     private float min_X = -2.2f, max_X = 2.2f;
 
     public bool canMove;
     private float move_Speed = 2f;
 
     private Rigidbody myBody;
 
     private bool gameOVer;
     private bool ignoreCollision;
     private bool ignoreTrigger = false;
 
     public float gravityScale = 10.0f;
  
     // Global Gravity doesn't appear in the inspector. Modify it here in the code
     // (or via scripting) to define a different default gravity for all objects.
  
     public static float globalGravity = -9.81f;
  
 
     void Awake(){
         myBody = GetComponent<Rigidbody>();
         myBody.useGravity = false;
     }
 
     void Start()  
     {
         canMove = false;
         move_Speed *= -1f;
         GameManager.instance.currentBox = this;
     }
 
     void Update()
     {
         if(!canMove)
             {Gravity();}
         MoveBox();
         
     }
 
     void MoveBox(){
         if(canMove){
             Vector3 temp = transform.position;
             temp.x += move_Speed * Time.deltaTime;
 
             if(temp.x > max_X){
                 move_Speed *= -1f;
             }
             else if(temp.x < min_X){
                 move_Speed *= -1f;
             }
             transform.position = temp;
         }
     }
     
     void Gravity ()
     {
         Vector3 gravity = globalGravity * gravityScale * Vector3.up;
         myBody.AddForce(gravity, ForceMode.Acceleration);
     }
 
     public void DropCube(){
         canMove = false;
     }
 
     void Landed(){
         if(gameOVer)
             return;
         ignoreCollision = true;
         ignoreTrigger = true;
         GameManager.instance.SpawnNewBox();
         GameManager.instance.MoveCamera();
     }
 
     void RestartGame(){
         GameManager.instance.RestartGame();
     }
 
 
     void OnCollisionEnter(Collision target){ 
         if(ignoreCollision)
             return;
 
         if(target.gameObject.tag == "Platform"){
             Debug.Log("Platform Collision");
             Invoke("Landed",2f);
             ignoreCollision = true;
         }
          if(target.gameObject.tag == "Box"){
             Invoke("Landed",2f);
             ignoreCollision = true;
         }
     }
 }
 

Blockquote

screenshot-2021-07-27-123002.png (24.9 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by New_Game_Ideas · Jul 27, 2021 at 01:20 PM

There is a simple solution when your cube touche the ground freeze the postions in code you can do it in OnCollisionEnter function. If you cannot do it here is a link with examples and futher information. https://answers.unity.com/questions/747872/freeze-rigidbody-position-in-script.html

You can also increase the drag (thus increasing mass to protect the speed same).

Comment
Add comment · Share
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

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

234 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

Related Questions

How can I drag an object with touch on X and Z axis without disrupting the gravity of the rigidbody? 0 Answers

Move ball object based on gravity 0 Answers

Can't get gravity to work on Character Controller 2 Answers

How to walk around a 3D sphere? 0 Answers

Disabling gravity for a Character Controller 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