- Home /
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!
Answer by debu · Oct 17, 2014 at 05:27 AM
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
I can't find a clue as per what is going wrong, any clues or leads would be very helpful.
thanks again, D
Your answer
Follow this Question
Related Questions
Midair Strafing 3 Answers
Align Parent object using child object as point of reference 3 Answers
Problem with a RigidBody and IsKinematic... I think 1 Answer
Player character moves without controller input 2 Answers
Is it possible to do inverse transformations, instead of moving complex groups of objects? 0 Answers