using UnityEngine;
using System.Collections;
public class sc_Player : MonoBehaviour {
float xspeed=0f;
float yspeed=0f;
float sp=8;
float grav = -1;
float gravlim= -12;
float jumppow = 18;
public Rigidbody Rbod;
// Use this for initialization
void Start () {
Rbod = (Rigidbody)gameObject.AddComponent ("Rigidbody");
Rbod.useGravity = false;
transform.rigidbody.constraints = RigidbodyConstraints.FreezePositionZ;
}
// turn's gravity off
//transform.rigidbody.contraints = rigidbody.contraints
void Update ()
{
xspeed = 0f;
if(Input.GetKey ("right")) xspeed= sp;
if(Input.GetKey("left")) xspeed = -sp;
yspeed+=grav;
if (yspeed <= gravlim)yspeed = gravlim;
if(Input.GetKeyDown("x")) yspeed = jumppow;
rigidbody.velocity = new Vector3(xspeed,yspeed,0);
transform.rotation = Quaternion.AngleAxis (0, Vector3.forward);
}
}
Here is my question, I want to use a cubed based collision detection, but for some reason when I tried to add a gravity variable, it made it impossible to move my cube ? I just don’t really know what’s constraining the right and left movement, I was thinking of doing some sort of raycast to stop the downwards momentum, but i don’t know is that’s really the problem,or a good solution.The odd thing is that I’m able to move right and left when I use a capsule instead of a cube.