Transform.Translate | Self | World

Hi,

I am working on a VR application with Google Cardboard, where in I am trying to simulate movement on click of the magnetic button.

My question is related to the movement, where in I am trying to move the user with Head Bobbing to simulate realistic walking. Following is the code snippet:

``````public class ControlCamera : MonoBehaviour {

float timer = 0.0f;
public float bobbingSpeed = 0.18f;
public float bobbingAmount = 0.2f;
public float midpoint = 1.0f;
public float horizontal = 10.0f;
public float vertical = 10.0f;

// Update is called once per frame
void Update ()
{
float waveslice = 0.0f;

if (Sensors.isMove)
{
// transform.Translate (Vector3.forward * Time.deltaTime);

if (Mathf.Abs(horizontal) == 0 && Mathf.Abs(vertical) == 0)
{
timer = 0.0f;
}

else
{
waveslice = Mathf.Sin(timer);
timer = timer + bobbingSpeed;

if (timer > Mathf.PI * 2)
{
timer = timer - (Mathf.PI * 2);
}
}

if (waveslice != 0)
{
float translateChange = waveslice * bobbingAmount;
float totalAxes = Mathf.Abs(horizontal) + Mathf.Abs(vertical);
totalAxes = (float) Mathf.Clamp (totalAxes, 0.0f, 1.0f);
translateChange = totalAxes * translateChange;

transform.Translate(Vector3.forward * Time.deltaTime);
transform.Translate(new Vector3(0.0f, (midpoint + translateChange), 0.0f), Space.World);
}

else
{
transform.Translate(Vector3.forward * Time.deltaTime);
transform.Translate(new Vector3(0.0f, (midpoint + translateChange), 0.0f), Space.World);
}
}
}
}
``````

I am trying to integrate the forward translate with the head-bobbing in the above code, one translate is Space.Self (forward motion) whereas the other translate is Space.World (head-bobbing).

Whenever I am trying to do both the things in separate lines of code only the head-bobbing is done whereas the forward translate doesnâ€™t happen.

Any help is appreciated, thanks in advance!

Both the line of code i.e.,

``````transform.Translate(Vector3.forward * Time.deltaTime);

transform.Translate(new Vector3(0.0f, (midpoint + translateChange), 0.0f), Space.World);
}
``````

are working fine independently.

thanks,
D