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 galaboy · Jul 22, 2013 at 08:30 AM · beginnerscriptingproblem

rigid body working wierd

am doing a side scroller game demo, in which my player is a ball. he has to move according to keyboard inputs and rotate too. Everything is working fine until he collides with another collider. The movement of the player gets wierd as he jumps, rotates and moves randomly. need help.

 using UnityEngine;
 using System.Collections;
 
 public class player_script : MonoBehaviour {
     
     public float speed = 10f;
     public float rotationSpeed = 30f;
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () 
     {        
         float amtToMove = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
         transform.Translate(Vector3.right * amtToMove);
         transform.Rotate(amtToMove * rotationSpeed, 0, 0);
         
         if(Input.GetKeyDown("space"))
         {
              rigidbody.velocity = new Vector3(0, 10, 0);
         }
     }
     
 }
Comment
Add comment · Show 6
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 Benproductions1 · Jul 22, 2013 at 08:44 AM 0
Share

Please format your code

avatar image YoungDeveloper · Jul 22, 2013 at 09:01 AM 0
Share

What collider are you using on your ball, and if it's mesh collider what's the polycount of your ball.

avatar image galaboy · Jul 22, 2013 at 09:03 AM 0
Share

iam using sphere collider that came with the sphere when it was created.

avatar image YoungDeveloper · Jul 22, 2013 at 09:18 AM 0
Share

okey, and what are the other objects its colliding with, cubes ?

avatar image Linus · Jul 22, 2013 at 09:22 AM 0
Share

I think line 23 rigidbody.velocity = new Vector3(0, 10, 0) gets a problem if the ball has rotated when colliding. As y is no longer up. If that is the case, try to reparent the ball under a transform that is not rotated. And do the jumping on the parent transform. Guess that does not work well if jumping by using physix though.

This http://answers.unity3d.com/questions/260191/getting-rigidbody-to-jump-by-changing-the-velocity.html might help then

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by $$anonymous$$ · Jul 22, 2013 at 10:18 AM

Maybe you need to lock constrains in rigidbody?

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 galaboy · Jul 22, 2013 at 03:33 PM 0
Share

thanks mate ur answer worked out. the problem was when the player collided with another collider its axis got rotated due to the impact.but when i freezed the rotation the axis got freezed resulting in no rotation due to impact. thanks once again.

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

18 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

Related Questions

On raycast hit remove Rigidbody 1 Answer

Incomprehensive auto death on 2D runner with energy depleting mechanics [Debugging] 1 Answer

Downsize A 3DS Model? 1 Answer

Nested Coroutines Waiting for Each Other 1 Answer

Lane moving vehicle 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