- Home /
Character refuses to fly
Hey guys, i am trying to make the player fly, but i can't make it work! I am using the Standard First Person Character, and i am trying to make him be able to fly when he enter the water so he will not be traped or something. The problem i am having is that he just doesn't fly. If i add my script to a cube or anything else, when i press space i can make them fly, but not my character! I tried removing it's scripts but still it doesn't go. Someone know why? Can you help me?
This is my script, you can test it if you want:
using UnityEngine;
using System.Collections;
public class Fly : MonoBehaviour
{
bool JumpPressed = false;
public float jumpAccelleration = 3;
void Update()
{
if (!JumpPressed)
JumpPressed = Input.GetKey(KeyCode.Space);
}
void FixedUpdate()
{
if (JumpPressed) GetComponent<Rigidbody>().AddForce(new Vector3(0, jumpAccelleration, 0), ForceMode.Impulse);
if (JumpPressed) JumpPressed = false;
}
}
Is your acceleration high enough? Remove gravity off your character, you should see yourself levitate when you press space.
Answer by tbenner · Dec 03, 2016 at 07:43 AM
I'll take a stab in the dark, but did you change the mass of your character? If the mass is too high, then the acceleration value probably would not have any effect. Since you say it works on cubes and you have removed all other scripts, I would compare the properties between a standard cube and your character.
Yeah, i changed to see that too and it still doesn't work.
You don' have the character's RigidBody set to kinematic right?
No, normal Rigidbody. That's why i don't have any idea of what is happening =\
It is possible that scripts on the Standard Character controller is interfering with your script. You may have to disable the script(s) just prior to flying, and re-enable after landing back.
It's a funny coincidence that you are commenting on this topic, given your user name.
Hah! that's funny, I didn't noticed until you mentioned it.
I am going to try literally disabling everything again, removing everything that i can until that prefab is literally a capsule with no mesh and a camera.
Yea, that would be the best approach, disable all, and start enabling one at a time, until it breaks. If I remember correctly, I ran into some similar issues, with Unity Character controller. I know they provide you with two types of controllers, physics based and non physics based. So, if you are using the physics one, it's possible to have issues with other scripts.
Okay, i am going to do the following:
For now, i am going to do as you said, and i am going to make another C# script from zero. I am going to disable all the scripts that the character have when he is underwater, and add ONLY the water mode script. I can add movement later.
$$anonymous$$y problem is, as i said, make the movement (i am not that good at using vertical and horizontal) and i am almost sure i am going to have some error if i disable all them at once... Anyway, i think this question is "solved". Could you make your comment as answer or something? Thanks.
Answer by Shrikky23 · Dec 05, 2016 at 03:51 PM
One different solution would be to send the Jumppressed bool to the character controller script. Add your condition in their script. That should make their script take your conditions into account.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to disable MouseLook in ingame pause. 1 Answer
Enable a component after a specific amount of time? 4 Answers
Relative AddForce 0 Answers