- Home /
Question by
BarkShark · May 11, 2011 at 12:45 PM ·
charactercontrollergravity
Gravity without character controller
Hello,
I'm creating a simple 2D platform and i'm using a character controller and the first person control script. Could someone please say me if theres a way to apply gravity and left right movement to an object. I also tried with a rigidbody attached to my object an checked gravity but that didn't work..
Thank you
Comment
Best Answer
Answer by YikYikHeiHei · Jul 27, 2011 at 11:35 AM
This script is not use character controller. You want the have gravity, you can add the rigidbody in you character
Update
enum TraXYZ {XY,XZ}
var TraXYZ : TraXYZ = TraXYZ.XY;
var moveSpeed = 6.0;
var rotateSpeed = 7.0;
function FixedUpdate()
{
if(TraXYZ == TraXYZ.XY)
{
var vector3MoveXY = Vector3(Input.GetAxis("Horizontal"), 0, 0);
transform.Translate(vector3MoveXY * moveSpeed * Time.deltaTime, Space.World);
}
else
{
var vector3MoveXZ = Vector3(0, 0, Input.GetAxis("Vertical"));
transform.Translate(vector3MoveXZ * moveSpeed * Time.deltaTime, Space.World);
}
if (this.rigidbody)
{
rigidbody.freezeRotation = true;
}
}
@script RequireComponent(CapsuleCollider)
@script RequireComponent(Rigidbody)
I am use this script too. So it is work.
Your answer
