Toba
August 11, 2012, 8:11am
1
Hi there. I’m working on a firs person adventure like Amnesia or Penumbra.
The idea is to create a smooth movement for the mouse: not to look directly to the mouse position but with a deceleration (with transition).
I did it and it works fine in my computer but when I test it on other computers it moves slower and even makes some drastic jumps.
The first time I thought the problem was the DT but I couldn’t find the mistake in the code.
Here is the code (I simplify it):
/* Constants: mouseSensitivityX, mouseSensitivityY, rotationYMin, rotationYMax and rotationLerpSpeed */
newRotation = new Vector3 ( currentRotation.x, currentRotation.y, currentRotation.z );
newRotation.y = newRotation.y + (Input.GetAxis( "Mouse X" ) * mouseSensitivityX * Time.deltaTime);
newRotation.x = Mathf.Clamp( newRotation.x - (Input.GetAxis( "Mouse Y" ) * mouseSensitivityY * Time.deltaTime), rotationYMin, rotationYMax );
currentRotation.x += ( newRotation.x - currentRotation.x ) * ( rotationLerpSpeed * Time.deltaTime );
currentRotation.y += ( newRotation.y - currentRotation.y ) * ( rotationLerpSpeed * Time.deltaTime );
I’m mising something? Is the DT necesary where I put it? Do you think there is a better way to do it?
Thank you!
you multiplying to Time.deltaTime twice.
try this:
if (!attributes.lockLookInX)
currentRotation.x = Mathf.Clamp(currentRotation.x + Input.GetAxis( "Mouse Y" ) * mouseSensitivityY * Time.deltaTime * rotationLerpSpeed, rotationYMin, rotationYMax);
if (!attributes.lockLookInY)
currentRotation.y = currentRotation.y + Input.GetAxis("Mouse X") * mouseSensitivityX * Time.deltaTime * rotationLerpSpeed;
eyes.localEulerAngles = V3.SetXResetYZ( currentRotation.x );
transform.eulerAngles = V3.SetYResetXZ( currentRotation.y );
Toba
August 27, 2012, 11:57pm
3
I check it on other computer and it continues not working.
In my computer it works fine but the speed continues changing when I check it on other computers.
Here is the code (updated):
mouseLookRotation.x = Mathf.Clamp( mouseLookRotation.x - (Input.GetAxis( "Mouse Y" ) * Time.deltaTime), rotationMin, rotationMax );
mouseLookRotation.y += Input.GetAxis( "Mouse X" ) * Time.deltaTime;
lookRotation = new Vector3 ( mouseLookRotation.x, mouseLookRotation.y, mouseLookRotation.z );
float lerpSpeed = lookLerpSpeed * Time.deltaTime;
if ( lerpSpeed > 0 )
{
Quaternion currentRotation = Quaternion.Euler( lookRotation );
head.rotation = Quaternion.Slerp( head.rotation, currentRotation, lerpSpeed );
head.localEulerAngles = new Vector3 ( head.localEulerAngles.x, 0F, 0F );
transform.rotation = Quaternion.Slerp( transform.rotation, currentRotation, lerpSpeed );
transform.eulerAngles = new Vector3 ( 0F, transform.eulerAngles.y, 0F );
}
Any idea?
Thank you.