0
votes

I'm having a few issues with a bit of game-logic. Right now I've got a setup that has the player use the new Samsung Galaxy S8 with the Gear-VR Headset + Gear controller to explore an environment. The current code is setup that the player can move forwards and backwards using the direction to which they're looking using a character controller and a calculation of the direction the camera is looking towards to move towards based on the 'touchpad' of the controller.

I have a horizontal and vertical axis (Based on the controller 'touch') that goes from -1.0 to 1.0 in a Vector2.

if (input.y > 0.0f || input.y < 0.0f || input.x > 0.0f || input.x < 0.0f) {
    Vector3 direction = new Vector3(cameraObject.transform.forward.x, 0, cameraObject.transform.forward.z);
    cC.Move(direction * walkSpeed * Time.deltaTime * input.y);
}

The above code translates the player forwards and backwards by calculating the direction the camera is looking at and moving 'towards' it, but what I also need is to 'strafe' to the left and right and can't seem to figure it out.

1
if (input.y != 0.0f || input.x != 0.0f) { ... } but from the code in the brackets I see you don't even use input.x so if statement can be even shorter: if (input.y != 0.0f) { ... }Nika Kasradze

1 Answers

1
votes

I haven't used the controller input before but I am assuming that input.x is left/right and input.y is forward/back is that correct?

I believe your character is only moving forward and backward because you are only using the transform.forawrd Vector of the cameraObject, which is only in the z direction and has no x component.

Try this (using transform.forward and transform.right):

cC.Move((cameraObject.transform.forward * input.y + cameraObject.transform.right * input.x) * walkSpeed * Time.deltaTime)