- Home /
Damp natural camera sway without a script - Is this possible?
Hi everybody,
Does anybody know whether there' are components or something similar that can be used to "damp" movement of a transform, i.e. without having to script that "damping" by hand?
Here's what I am trying to do:
I have a camera attached to my player model for generating the 1st person view. I've explicitely attached it to one of the bones to get immersive "camera sway".
This works very good. However, the sway is quite strong, as it translates 1:1 from the bone movement. So I want to reduce it a bit to get a more realistic, smoother feeling. Unfortunately, there's no bone in my model that behaves exactly the way that would match my expectations for the camera (there's no "camera bone", of course :)). And I wouldn't want to start changing my bone animations only for that, because that would restrict animations too much only for the purpose of getting a smoother camera.
I know that I could possibly solve this problem by some scipting, using functions like Mathf.SmoothDamp() etc. But I expect this to become quite complex, and I'd prefer not to rely on too heavy scripting for such a specific need.
That's why I am looking for a more light-weight solution (if one exists).
I've already tried to experiment with rigidbodies, but to no success.
Thanks alot!!
How long did you spend messing with joint components?
They act strange at first, and playing with the variables makes them even worse. But once you figure out the ranges and which kind you want (a spring joint?) they aren't that bad.
I tried this for about 1 hr. But I must say that I didn't get very far. I came to the conclusion that it may become quite hard to achieve what I am trying to do with joints: I tried with fixed, spring and configurable joints, but always ended up having my camera and the joined bone being "contracted" somehow. With the result that my player's spine always get's bowed down.
I admit that I finally went over trying the scripting approach proposed by steinbitglis below, and this solved my problem much easier. I suppose that joints aren't a bad idea at all, but in my case (maybe only by chance) the other solution turned out to be more suitable.
Thanks anyway! Your hint drew my attention to joints, and I am sure that I'll use them anyway before long.
Answer by steinbitglis · Feb 23, 2013 at 08:38 PM
You could try to make your camera read the position and rotation from where it is now, but not actually be a child transform.
Something like this:
class DampedTransform (MonoBehaviour):
public target as Transform
public tightness = 1f
def Update ():
transform.position = Vector3.Lerp(target.position, transform.position, Mathf.Pow(0.98f, Time.deltaTime * 60f * tightness))
transform.rotation = Quaternion.Slerp(target.rotation, transform.rotation, Mathf.Pow(0.98f, Time.deltaTime * 60f * tightness))
Thanks, steinbitglis! I managed to solve my issue with your suggestion.
In my case, the only slight difference was that I still had to attach my camera to the player root object (as a child), to ensure that it neatly moves together with it.
Then I created a script like described above and set the *eye bone" as the target.
Apart from some picky details that I had to elaborate (no sense in posting them here) it basically worked!
thumbsup
Sorry for taking so long to accept your answer! I wasn't aware that I had only hit the "vote up" button. Now I've noticed - better late than never! :)