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 Dutti · Jul 30, 2012 at 07:56 PM · physicsrigidbodymaterials

2 cubes objects bounce off eachother

Hello, I have made a 3D versjon of pong.

I have a a paddle that player1 controls with this script. It works fine all directions as it should.

It is a cube object with rigidBody. It has a pysical material on it and on all walls (plane with mesh colider) so the ball can bounce of it.

PysMat: Friction = 0 and Bounciness = 1.

The problem I am trying to solve is when my cube(paddle) hits any wall it starts to "shake and bounce" making it uncontrollable (looks like it gains force in some direction, if I let go off the controls it starts to move on its own). I have at least locked it from spinning of x,y axis by checking all 3 freeze rotation boxes.

I have the same problem without the pysical materials, it just shakes alittle differently. Is there a way I can make 'em not hit each other or constrain the movements of my player controlled cube?


my script for controlling the paddle (cube)


var keyboardSpeed = 20.0;

function FixedUpdate () {

 var keyboardX = Input.GetAxis("Horizontal") * keyboardSpeed * Time.deltaTime;
 var keyboardY = Input.GetAxis("Vertical") * keyboardSpeed * Time.deltaTime;

 var newPos = rigidbody.position + Vector3(keyboardX, keyboardY, 0.0);

 rigidbody.MovePosition(newPos);

}

@script RequireComponent(Rigidbody)

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

2 Replies

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

Answer by ScroodgeM · Jul 30, 2012 at 09:33 PM

solution 1: you should mark rigidbody as kinematic if you want control it directly

solution 2: use 'add force' instead of 'move position' if you want to control it and let physics work

edit: fast example of what i mean

http://zammyart.com/UA/RigidbodyTester/WebPlayer.html

arrows or WASD - give ball a force

void Update()
{
    rigidbody.AddForce(50f * new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical")));
}

sources

http://zammyart.com/UA/RigidbodyTester/rigidbodytest.unitypackage

Comment
Add comment · Show 16 · 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 Dutti · Jul 30, 2012 at 10:18 PM 0
Share

I do not think solution 1 will work here without rewriting my code, but I will try solution 2 tomorrow, thanks.

avatar image Dutti · Jul 31, 2012 at 09:30 AM 0
Share

I have tried solution 1 is kinematic, the the paddle just goes through the wall.

Solution 2 just made the steering harder and still bounces on the wall.

I have tried transform.position.x += transform.forward moveSpeed Time.deltaTime; ins$$anonymous$$d. Still same problem.

By adding drag i got the paddle to not drift of after hitting a wall.

Found that it was interpolate settings that made all the difference. By setting interpolate to none then the problem is livable combined with high drag settings.

avatar image ScroodgeM · Jul 31, 2012 at 09:37 AM 0
Share

you should generally select one of two ways:

  • you control object manually. it means rigidbody is marked as kinematic, you calculate all movements, speeds, collisions etc in scripts, and apply it directly to object

  • you don't control object manually. it means rigidbody is not marked as kinematic, unity calculates all physics interaction, and you able to change only forces that affects on object. like a car in reallife - you just can change force and rotate wheels.

so again. solution 2.

so if you will let physics to be calculated automatically and affect object with realistic forces, you'll get a realistic physics.

try to apply low forces to object. it can bounces cause mass is low and forces are high

avatar image Dutti · Jul 31, 2012 at 09:45 AM 0
Share

Can you point me in the right direction for making my object not go through the walls when they hit if I use is kinematic? I needs to stop right beside the walls.

But I use physics when the ball hits the paddle. So the object should not be kinematic at that point I think.

avatar image ScroodgeM · Jul 31, 2012 at 10:22 AM 0
Share

i'd edit answer

Show more comments
avatar image
0

Answer by Dutti · Jul 31, 2012 at 10:27 AM

I needed to have my paddle rigidBody Interpolate settings set at none and drag at something high like 100 to make the problem less noticeable.

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 ScroodgeM · Jul 31, 2012 at 10:34 AM 0
Share

look at demo in my answer - is that what you need?

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to get Satisfying Collision Physics 1 Answer

Character with box collider sticks to walls 0 Answers

How to make Rigidbody.AddForce less delayed in Unity3D? 0 Answers

Avoid bouncing when ground move down 1 Answer

Tracked Ride Physics Simulation 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