Posts: 16
Threads: 4
Joined: Nov 2020
Reputation:
0
Hello,
So I have a ball attached to a rope that is attached to a pole. I don't want to grab the rope directly, but I want the user to be able to grab the ball that is attached to the rope and throw it around. Currently, when I try to move the ball transform in the editor view during runtime, it does not work very smoothly. If I change the ball transform too much, it glitches out and the rope spazzes out. I have checked to make sure the ball and rope are not colliding. Even in the "chains" demo, I tested it and if you try to move the ball during runtime via the editor it glitches out the rope and the rope flies everywhere. Please if you could give me some advice that would be very much appreciated.
Posts: 6,347
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
19-12-2020, 09:15 AM
(This post was last modified: 19-12-2020, 09:18 AM by josemendez.)
(19-12-2020, 03:53 AM)Navvv Wrote: Hello,
So I have a ball attached to a rope that is attached to a pole. I don't want to grab the rope directly, but I want the user to be able to grab the ball that is attached to the rope and throw it around. Currently, when I try to move the ball transform in the editor view during runtime, it does not work very smoothly. If I change the ball transform too much, it glitches out and the rope spazzes out. I have checked to make sure the ball and rope are not colliding. Even in the "chains" demo, I tested it and if you try to move the ball during runtime via the editor it glitches out the rope and the rope flies everywhere. Please if you could give me some advice that would be very much appreciated.
If the ball is a rigidbody, moving it around using its transform does not make much sense as that ignores physics. It just sets its position, ignoring any forces and/or constraints applied to it.
You will be able to overstretch the rope ignoring any forces applied by the it, and the ball will move out of sync with the physics update (not in FixedUpdate, but in Update) causing all sorts of weird issues. This would happen with regular joints too.
Non-kinematic rigidbodies should be moved using forces/impulses/velocity changes, specially if they’re constrained (be it using joints and/or Obi attachments). See the “wraprope” sample scene: https://youtu.be/7ugSN7laNd4
Posts: 16
Threads: 4
Joined: Nov 2020
Reputation:
0
(19-12-2020, 09:15 AM)josemendez Wrote: If the ball is a rigidbody, moving it around using its transform does not make much sense as that ignores physics. It just sets its position, ignoring any forces and/or constraints applied to it.
You will be able to overstretch the rope ignoring any forces applied by the it, and the ball will move out of sync with the physics update (not in FixedUpdate, but in Update) causing all sorts of weird issues. This would happen with regular joints too.
Non-kinematic rigidbodies should be moved using forces/impulses/velocity changes, specially if they’re constrained (be it using joints and/or Obi attachments). See the “wraprope” sample scene: https://youtu.be/7ugSN7laNd4
Ah, thanks so much. That clears up a lot of confusion since I haven't worked with Unity Physics much before in my previous games. So basically, when I want the player to grab the ball, I will turn iskinematic on and parent it to the player's hand. Then, when the player is about to hit/serve the ball, I will turn iskinematic off. Does this sound correct? If you can give me any tips as well on exactly what point should I disable iskinematic and unparent the ball from the player's hands I would really appreciate that. Should I disable it exactly when the player hits the ball, or before? If before, how long before?
Posts: 6,347
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
21-12-2020, 08:52 AM
(This post was last modified: 21-12-2020, 08:53 AM by josemendez.)
(19-12-2020, 10:23 PM)Navvv Wrote: Ah, thanks so much. That clears up a lot of confusion since I haven't worked with Unity Physics much before in my previous games.
Obi is aimed at advanced users, so you might have a hard time using it if you're not familiar with how physics work. Just a forewarning. Don't be discouraged though!
(19-12-2020, 10:23 PM)Navvv Wrote: So basically, when I want the player to grab the ball, I will turn iskinematic on and parent it to the player's hand. Then, when the player is about to hit/serve the ball, I will turn iskinematic off. Does this sound correct? If you can give me any tips as well on exactly what point should I disable iskinematic and unparent the ball from the player's hands I would really appreciate that. Should I disable it exactly when the player hits the ball, or before? If before, how long before?
Yes, that's the standard approach to "grabbing" rigidbodies (regardless of them being constrained by rope/joints of not). You should enable it right when all "grab" conditions are met (the ball is close to the player's hand, and the player has pressed the "grab" button/key or something like that) and disable it once they aren't. The exact time duding the frame at which you enable/disable it isn't very important: if physics have already been updated during that frame, the change will be made effective during the next frame.
Posts: 16
Threads: 4
Joined: Nov 2020
Reputation:
0
(21-12-2020, 08:52 AM)josemendez Wrote: Obi is aimed at advanced users, so you might have a hard time using it if you're not familiar with how physics work. Just a forewarning. Don't be discouraged though!
Yes, that's the standard approach to "grabbing" rigidbodies (regardless of them being constrained by rope/joints of not). You should enable it right when all "grab" conditions are met (the ball is close to the player's hand, and the player has pressed the "grab" button/key or something like that) and disable it once they aren't. The exact time duding the frame at which you enable/disable it isn't very important: if physics have already been updated during that frame, the change will be made effective during the next frame.
This is a game I've been wanting to make for a while now, so I'm definitely willing to do whatever it takes to learn!
Thank you for the clarification. No more questions for now .
|