Gravity is not working
could someone please explain why the gravity is not taking effect?
using System.Collections; using UnityEngine.Scene$$anonymous$$anagement;
public class PlayerControlls : $$anonymous$$onoBehaviour { private float speed = 10.0f; private Rigidbody rb; // private float gravity = 9.8f; private int deaths; private int gemCount; private int nextScene; // CharacterController cont;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody>();
//cont = gameObject.GetComponent<CharacterController>();
}
void OnLevelWasLoaded(int level) {
nextScene = level + 1;
}
void OnTriggerEnter (Collider obj) {
// kill player when they fall off
if (obj.CompareTag("killZone")) {
Scene$$anonymous$$anager.LoadScene (Scene$$anonymous$$anager.GetActiveScene ().name);
deaths++;
}
// portal leads to next scene
if (obj.CompareTag("portal")) {
Scene$$anonymous$$anager.LoadScene (nextScene);
deaths++;
}
//collects yellow gems
if (obj.CompareTag("yellowGem")) {
Destroy (obj.gameObject);
gemCount++;
}
}
public int getGemCount() {
return gemCount;
}
void FixedUpdate () {
Debug.Log (gemCount);
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical) ;
rb.AddForce(movement * speed);
// if (!cont.isGrounded) { // movement.y -= gravity;
// }
}
void Update () {
}
}
Your answer
Follow this Question
Related Questions
Allowing player to glide/fall slowly 2 Answers
Change player gravity by pressing a key? 1 Answer
I added Rigidbody to my cube and now it goes super fast when i move! 0 Answers
Gravity issue on MouvementController using RigidBody when going down a slope 0 Answers
Adding Gravity to a game object to make a black hole sucking effect. 1 Answer