Quantcast
Channel: Questions in topic: "swimming"
Viewing all articles
Browse latest Browse all 107

Underwater Swimming

$
0
0
Hi, I am currently using the standard Unity first person controller and I am trying to simulate underwater swimming. I understand that I need to set the first person controller movement to the cameras rotation to simulate the ability to 'swim' (basically flying in the direction of the camera). ---------- The script I have so far semi-works. It checks that i am under water and then when I press the directional keys it will move in the direction I am facing the camera, but the issue is it does this very slowly. ---------- For example if I enter the water and point the camera directly down and press W, the player will move forwards along the water plane and will eventually move 'down' but does not go directly to the forward position I am pointing. I think I am missing something rather basic and I have thought perhaps I need to set the rotation directly but I am struggling to find the correct solution for this. Any help or pointers is appreciated! if (Input.GetKey(KeyCode.W)) { transform.Translate(Vector3.forward * Time.deltaTime * underwaterSpeedForward, Camera.main.transform); } if (Input.GetKey(KeyCode.S)) { transform.Translate(-Vector3.forward * Time.deltaTime * underwaterSpeedBack, Camera.main.transform); } if (Input.GetKey(KeyCode.D)) { transform.Translate(Vector3.right * Time.deltaTime * underwaterSpeedStrafe, Camera.main.transform); } if (Input.GetKey (KeyCode.A)) { transform.Translate (-Vector3.right * Time.deltaTime * underwaterSpeedStrafe, Camera.main.transform); } if (Input.GetKey (KeyCode.Space)) { transform.Translate (Vector3.up * Time.deltaTime * upSpeed); }

Viewing all articles
Browse latest Browse all 107

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>