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 Zewde · Dec 01, 2015 at 06:16 AM · rigidbody2dcollidersphysics2dcollision detection

rigidbody not moving

Hey guys, i'm new to unity but I have android studio experience looking to see how the game industry is !

So i have a ball which is a rigidbody with a circular collider which is located between two walls. The ball is moved to the right when right arrow is pressed and left when left arrow is pressed with transform.position . The initial problem was that the ball was going through the walls even though it shouldn't, because I was using transform.position instead of rigidbody.moveposition which was messing with the physics engine (from what I read here). Now I am trying to use rigidbody.moveposition but the object is not moving anymore :

Here's a video to help you guys get my situation, everytime you hear a fairly loud bang it means i'm hitting either left or right mouse on keyboard :

http://screencast.com/t/7SYxQXfCwMeZ

(Script attached to the ball)

 using UnityEngine;
 using System.Collections;
 
 public class ballscript : MonoBehaviour {
     
     public Vector3 target = Vector3.zero;
     public Vector3 velocity = Vector3.zero;
     public float smoothTime = 0.3F;
     public bool right = false;
     public bool left = false;
     public Rigidbody rb;
     
     public float health = 100;
 
 
     // Use this for initialization
     void Start () 
     {
         rb = GetComponent<Rigidbody> ();
     }
 
     IEnumerator Example() {
         yield return new WaitForSeconds(0.0525f);
         left = false;
         right = false;
     }
 
     // Update is called once per frame
     void FixedUpdate () 
     {
 
 
 
         if (right == true) // OBJECT DOESN'T MOVE.
         {
 
             target.x = rb.position.x + 18;
             target.y = rb.position.y;
             target.z = -1;
             rb.MovePosition(Vector3.SmoothDamp (transform.position, target, ref velocity, smoothTime)); 
 
             StartCoroutine(Example()); // NEVER CALLED.
 
         }
 
         if (left == true) // OBJECT DOES MOVE.
         {
 
             target.x = transform.position.x - 18;
             target.y = transform.position.y;
             target.z = -1;
             transform.position = Vector3.SmoothDamp (transform.position, target, ref velocity, smoothTime); 
             StartCoroutine (Example ()); //CALLED.
 
         }
 
 
     }
 
 
     void OnBecameInvisible()
     { 
         Time.timeScale = 0;
         Destroy (gameObject);
         Debug.Log ("BALL HAS BEEN DESTROYED");
     }
 
 
     void Update()
     {
 
         if (Input.GetKeyDown (KeyCode.RightArrow)) 
         {
 
             right = true;
         }
 
         if (Input.GetKeyDown (KeyCode.LeftArrow)) 
         {
             left = true;
         }
 
 
     }
 }
 

BALL: http://content.screencast.com/users/Loftyy/folders/Jing/media/9edeab36-db0b-4aa5-9b23-e4d0aba67a1f/ball.png

WALL: http://content.screencast.com/users/Loftyy/folders/Jing/media/94a5b966-e9e0-4ad6-8c05-c5af1945d5e0/2015-11-30_0026.png

I hope someone can help me, i'm really determined to fix this and continue on my endeavor.

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 Arju2011 · Dec 01, 2015 at 08:25 AM

You need to attach your rigidbody to your script.

alt text


rigidbody.png (78.8 kB)
Comment
Add comment · Show 1 · 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
avatar image Zewde · Dec 01, 2015 at 10:08 PM 0
Share

hey! thanks but somehow, my game/project got corrupted and deleted for some reason :/ I will work on it. Are you a unity developper?I'm new to game developping and I'd like to speak with someone who knows about Unity through facebook/whatsapp or something. Completely understand if you don't want to :) have a good day!

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

(2D) Rigidbody slides a bit through Box Collider 1 Answer

Which object needs to be the trigger? 2 Answers

Dealing with weirdly shaped character (2D) 0 Answers

Physics 2D with tile collider corner problem 2 Answers

Collision detection for the next frame 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