Flying Character

Another question, hurray!

How do I make a “flying” character? (Move with arrows/WSAD, look with the mouse) Can I edit the First Person Controller Prefab so gravity doesn’t apply to it or something like that?

Do you want a character that usually walks, but can also fly sometimes, or something like an aeroplane?

Don’t know about AaHaa, but I sure would like the former. I’m very new at this and would love to add the ability for my character to fly as well as walk. Knowing almost zip about scripting all I have been able to do is let him jump with gravity really reduced.

Uuuhm… I need something like this:
W: Move forward
S: Move backward
A: Move left
D: Move right
Space: Go up
random key: Go down

A character without any gravity, but with the ability to rise and fall in height, like a swimming or flying character.

Perfectly put. Me, too.

Okay how about this.

P to go up, Space to go down. Use mouse “turn character”.

void Update()
	{
		if(gameObject!=null  gameObject.GetComponent(typeof(CharacterController)) )
		{

			CharacterController cc = (CharacterController)gameObject.GetComponent( typeof(CharacterController));

			float rotateSpeed = 10.0f;
			float rotationY = Input.GetAxis ("Mouse X") * rotateSpeed;
			transform.Rotate (0 , rotationY , 0); 
			
			float moveSpeed = 40.0f;
			float dt = Time.deltaTime;
			float dy =  0;
			if(Input.GetKey(KeyCode.Space))
			{
				dy = moveSpeed * dt;
			}
			if(Input.GetKey(KeyCode.P))
			{
				dy -= moveSpeed * dt;
			}
			float dx = Input.GetAxis("Horizontal") * dt * moveSpeed;
			float dz= Input.GetAxis("Vertical") * dt * moveSpeed;
			
			cc.Move(transform.TransformDirection(new Vector3(dx, dy,dz))  );
		}

	}
2 Likes

I have seen the example of RussianMadMan for SSAO which is using the character control you are looking for.

Download his example from: http://forum.unity3d.com/viewtopic.php?t=25765

and see if that is what you’re looking for.

Thanks very much, aiursrage2k

Unfortunately I am so new at this I don’t know what to do with your script. Does it go inside another script? Is it java, C Sharp, etc?

Sorry to be such a pain. I started trying to learn scripting over the weekend, only to realize that I don’t have enough extra time to do it justice. (The last time I did any programming it was in basic- long before the words visual and basic were used in the same sentence. Kinda ages me, doesn’t it.)

Is this script in js or cs?

OMG You are the best thanks so much I was searching for a tutorial for that but then I saw your code and it was AWESOME

Its c sharp its the main code the unity engine uses the most(I think it uses only c#). Also, I don’t know if you learned or something but you must make a 3d model then attach character controller and then make a script and attach to it and copy that code to the update void I hope it will help you if you didn’t find any solution