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 /
This question was closed Mar 06, 2019 at 08:55 PM by aidan7501 for the following reason:

Irrelevant, I am working towards a different solution

avatar image
0
Question by aidan7501 · Feb 25, 2019 at 07:09 PM · physicsrigidbodyrigidbody physicsforces

Move rigidbody to position and still have forces act on it

I am trying to create a system that lets the player pick up and carry around a rigidbody gun where it moves along with the player, while still reacting to collisions so that it can bump into walls and things like that.

I used the answer from here Stopping a rigidbody at target to make the gun move and stop when it gets to the position it needs to be. It works like it should, but I need to make it so that when the gun gets to the position, it will move along with the velocity of the player which is also a rigidbody.

So then I added the velocity of the player to the toVel variable, but now when I move around the gun is very jerky. Here is the code... Also a video showing my problem, see how it's jerky when moving side to side when aiming down sights... My video

And some big inspiration from this video... UE4 - Weapon collision vs world

 void FixedUpdate ()
 {
 if(beingHeldByPlayer)
 {
 Vector3 dist  = moveToPos - transform.position;
 Vector3 tgtVel = Vector3.ClampMagnitude ((toVel * dist) + playerObj.GetComponent <Rigidbody>().velocity, maxVel) ;
 Vector3 error = (tgtVel - rb.velocity);
 Vector3 force = Vector3.ClampMagnitude ((gain * error), maxForce);
 rb.AddForce (force);
 }
 }




I know I shouldn't use getcomponent in an update loop too, I'm just trying to get things working.

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 xxmariofer · Feb 25, 2019 at 07:46 PM 0
Share

hello, i would try using vector3.movetowards

  Vector3 tgtVel = Vector3.$$anonymous$$oveTowards(rb.velocity * (toVel * dist) + playerObj.GetComponent <Rigidbody>().velocity, maxVel) ;

you will have to addapt maxvel to this new method test it and tell me if it worked :)

avatar image aidan7501 xxmariofer · Feb 25, 2019 at 08:11 PM 0
Share

@xxmariofer Using movetowards made it less jerky, but I still have the problem that when ai$$anonymous$$g down sights, it does not follow along with the player exactly, it still lags behind which is not ideal

avatar image xxmariofer aidan7501 · Feb 25, 2019 at 08:37 PM 0
Share

hello, then what you are looking for is diviging the x and y velocitys. making the x y and z values "movetowards" at different velocitys, is the same method as my previous answer but you can use the $$anonymous$$athf.$$anonymous$$oveTowards to iterate all 3 velocitys separatly.

Show more comments

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

190 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

Related Questions

Solar System Simulator Orbits Not Working 2 Answers

Rotate child object under RigidBody parent 0 Answers

Rigidbody climbing stairs 2 Answers

Can't set position of Rigidbody precisely 0 Answers

Physics update rate problems 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