Search Unity

[Problem] Slopes, Gravity

Discussion in 'Physics' started by CleanWater, May 14, 2015.

  1. CleanWater

    CleanWater

    Joined:
    May 10, 2015
    Posts:
    5
    Hi,

    I wrote the following code:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class playerScript : MonoBehaviour {
    5.  
    6.     // Declarando as variaveis
    7.     public float speed;
    8.    
    9.     private float _x;
    10.     private float _y;
    11.  
    12.     // Use this for initialization
    13.     void Start () {
    14.  
    15.     }
    16.    
    17.     // Update is called once per frame
    18.     void FixedUpdate () {
    19.         float h = Input.GetAxis ("Horizontal");
    20.         float v = Input.GetAxis ("Vertical");
    21.  
    22.         _y = v * speed;
    23.         GetComponent<Rigidbody>().velocity = transform.forward * _y;
    24.  
    25.         // Girando
    26.         _x += h * speed;
    27.         transform.rotation = Quaternion.Euler (new Vector3(0f, _x, 0f));
    28.     }
    29. }
    I want to make this character move like in Resident Evil/Silent Hill from PS1.

    It moves right, until I have to go up a slope. Actually it goes up, but when coming down, the gravity looks like it is on Moon.
    I did a test and let my player box fall down with another box with no script. The "empty" box falls right, the player "floats" down until hitting the ground. I'm using the rotation constraints in the player.

    What I'm doing wrong, can someone explain it to me?

    Thanks in advance.