Everything looks like it should work, but I'm getting an error on line 18. Any suggestions? (Sorry if there is a code input thing for the forums, I can't find one. The red line is where there's an error) -------------------------------------------------------Code----------------------------------------------------------- using UnityEngine; using System.Collections; public class Movement : MonoBehaviour { public float spd = 6.0f; public float jumpSpeed = 8.0f; public float grav = 20.0f; Vector3 moveDirection = new Vector3(0,0,0); // Update is called once per frame void Update () { CharacterController controller = GetComponent<CharacterController>(); if (controller.isGrounded){ /*We are grounded to start off, so recalculate move direction directly from axes*/ moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= spd; if (Input.GetKey(KeyCode.LeftShift)){ moveDirection.y = jumpSpeed; } } //Apply gravity moveDirection.y -= grav * Time.deltaTime; //Move the controller controller.Move (moveDirection * Time.deltaTime); } }
Code tag is here: http://forum.unity3d.com/threads/134625-Using-code-tags-properly What is the error message? but most likely it needs .. = new Vector3(..
Doesn't a character controller already account for gravity? In essence, are you not doubling its effect by adding it in yourself? Could be wrong but its worth a shot just commenting out that part.
Hmm... seems to be more stuff there too. So, whether you are grounded or not your gravity calculation is being applied, which means it could be moving your player or jetpack below the terrain or surface that it is standing on. So change the Vector3 to "new Vector3" like mgear suggested, but also but an if (!isGrounded) check around your gravity calculation and see if it still vibrates.
If those public fields aren't having their values overwritten in the inspector, then you have specified a jump speed of 8 and a gravity speed of 20. That means with the jump pack firing, you have a net vertical speed of -12. Or at least you would, except that gravity is being multiplied by Time.deltaTime (and then you multiply the whole moveDirection vector by Time.deltaTime again afterwards). Which means that the actual strength of your gravity is going to change based on your framerate.