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 Calesurf · Jun 05, 2015 at 02:00 AM · collisionrigidbodyforcevectorrigidbody.addforce

rigidbody problem

Hey, I am making a pokemon like game but you actually play and battle with the pokemon in the world. I control the pokemon with rigidbody.AddForce. That works perfectly. The problem comes when I bump into another rigidbody it will act funny after I bump into it. It is like the force of the bump is still being applied to my rigidbody. It will continually slowly move or jiggle around in the vector of the other rigidbody. I want to stop this from happening. I don't know how. The same thing also occurs with the rigidbody I touched. I tried increasing the mass and drag but it still happens. When I increase the mass it has a less affect on me but a increased affect on the other rigidbody. Which I also don't want.

Here is the code to make me move.

 var spawnPoint : GameObject;
 var delay : boolean;
 var delay1 : boolean;
 
 function Update () {
     //rotate towards mouse
     var playerPlane = new Plane(Vector3.up, transform.position);
  
     var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
 
     var hitdist = 0.0;
 
     if (playerPlane.Raycast (ray, hitdist)) {
         var targetPoint = ray.GetPoint(hitdist);
         var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
         transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, speed * Time.deltaTime);
     }
     // move
     if(Input.GetKey("w")){
         //force is high because drag is really high
         rigidbody.AddForce(transform.forward * 4000);
         
     }
      if(Input.GetKey("s")){
         rigidbody.AddForce(transform.forward * -3600);
     }
     //attack
     if(Input.GetMouseButtonDown(1) && !delay){
         delay = true;
         var attack = Instantiate(Attack1, spawnPoint.transform.position, spawnPoint.transform.rotation);
         attack.rigidbody.AddForce(transform.forward * 800);
         Delay();
     }
     if(Input.GetMouseButtonDown(0) && !delay1){
         delay1 = true;
         var attack1 = Instantiate(Attack2, spawnPoint.transform.position, spawnPoint.transform.rotation);
         attack1.rigidbody.AddForce(transform.forward * 800);
         Delay1();
     }
 }
 
 function Delay(){
     if(delay){
         yield WaitForSeconds(1);
         delay = false;
     }
 }
 
 function Delay1(){
     if(delay1){
         yield WaitForSeconds(.2);
         delay1 = false;
     }
 }
 
 

  
Comment
Add comment · Show 4
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 Binxalot · Jun 05, 2015 at 02:34 AM 1
Share

Are you resetting each of the properties for the rigidbody on collision? You would zero out things like angular velocity, velocity, gravity true/false etc, put it all in a function and call it on impact, that'll zero out any forces on the rigidbody. If you need to have a bounce you can use physics materials.

avatar image barbe63 · Jun 05, 2015 at 08:10 AM 0
Share

You are moving rigidbody with addforce in an update. That could bring bad things.

Try to use a FixedUpdate()

avatar image Calesurf · Jun 05, 2015 at 03:30 PM 0
Share

It still occurs when I use FixedUpdate(){

Binxalot how would I do that would it look like this and if so it doesn't work

 function OnCollisionStay(other : Collision){
     rigidbody.velocity = Vector3(0,0,0);
     rigidbody.AddForce(transform.forward * 0);
     rigidbody.AddForce(transform.right * 0);    
 }
avatar image Calesurf · Jun 05, 2015 at 03:46 PM 0
Share

Found the problem it was a problem with angular velocity. All I Had to do was set rigidbody.angularVelocity = Vector3(0,0,0) when it has a collision with something else.

1 Reply

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

Answer by Calesurf · Jun 05, 2015 at 03:47 PM

All I had to do was put this on my move script

 function OnCollisionStay(other : Collision){
     rigidbody.velocity = Vector3(0,0,0);
     rigidbody.AddForce(transform.forward * 0);
     rigidbody.AddForce(transform.right * 0);
     rigidbody.angularVelocity = Vector3(0,0,0);    
 }

not sure if you need the AddForce ones but it works fine with them

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

22 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

Related Questions

Character Controller meets Rigidbody 1 Answer

How to make a Vector with the same angle as a certain object? 1 Answer

Tossing an object with the correct force at any distance from another so that it collides with the other 1 Answer

How to hit gameobjects to go into the opposite direction of hit? 1 Answer

Manually Apply Cars Collision Response Force 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