# Mathf.SmoothDampAngle Question

 0 I have a question regarding the Mathf.SmoothDampAngle function. I have a plane, which I am trying to tilt randomly in different directions. I want it to be constrained to a maximum x rotation and a maximum z rotation. I do not want it to rotate on the y axis (spin) yet. This is the code I am using, and it does what I want, but it does not do it smooth enough, neither does it seem to use the whole range of the constraints that I put. (Which are 45 degrees in each direction) My code is as follows: `````` rotX = Random.Range (MIN_ROTATION, MAX_ROTATION); rotY = Random.Range (MIN_ROTATION, MAX_ROTATION); rotZ = Random.Range (MIN_ROTATION, MAX_ROTATION); float xAngle = Mathf.SmoothDampAngle (transform.eulerAngles.x, rotX, ref velocity, smooth, Mathf.Infinity, Time.deltaTime); float yAngle = Mathf.SmoothDampAngle(transform.eulerAngles.y, rotY, ref velocity, smooth); float zAngle = Mathf.SmoothDampAngle (transform.eulerAngles.z, rotZ, ref velocity, smooth, Mathf.Infinity, Time.deltaTime); Vector3 newRot = new Vector3(xAngle, 0.0f, zAngle); rigidbody.transform.rotation = Quaternion.Euler(newRot); ``````Does Anyone have any ideas as to what I can change to make the platform tilt back and forth on the x and z axis smoothly with a controllable speed and controllable range? more ▼ asked May 12 '12 at 11:15 PM Taliesen01 0 ● 1 ● 2 ● 2 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 Well noone answered me but I think I might have solved my problem, I will post it in case anyone else might have need of this answer. Basically the problem is that since every update it was generating a random target for the smoothdampangle to tilt to, it never actually reached its goal. That made it look jerky. I solved this rather simply by putting a fixed time step based on delta time which says only recalculate a new target every second. `````` if(time >= 1){ rotX = Random.Range (MIN_ROTATION, MAX_ROTATION); rotY = Random.Range (MIN_ROTATION, MAX_ROTATION); rotZ = Random.Range (MIN_ROTATION, MAX_ROTATION); time = 0; } float xAngle = Mathf.SmoothDampAngle (transform.eulerAngles.x, rotX, ref velocity, smooth, Mathf.Infinity, Time.deltaTime); float yAngle = Mathf.SmoothDampAngle(transform.eulerAngles.y, rotY, ref velocity, smooth); float zAngle = Mathf.SmoothDampAngle (transform.eulerAngles.z, rotZ, ref velocity, smooth, Mathf.Infinity, Time.deltaTime); Vector3 newRot = new Vector3(xAngle, 0.0f, zAngle); transform.rotation = Quaternion.Euler(newRot); time += Time.deltaTime; ``````If any of you can think of a better way of doing this, please post here and tell me. more ▼ answered May 13 '12 at 01:07 AM Taliesen01 0 ● 1 ● 2 ● 2 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x2155
x96
x2

asked: May 12 '12 at 11:15 PM

Seen: 608 times

Last Updated: May 13 '12 at 01:07 AM