Unity3D Android - Move your character to a specific x position

Posted by user3666251 on Game Development See other posts from Game Development or by user3666251
Published on 2014-05-31T15:20:52Z Indexed on 2014/06/01 3:53 UTC
Read the original article Hit count: 227

Filed under:
|
|

Im making a new game for android and I wanted to move my character (which is a cube for now) to a specific x location (on top of a flying floor/ground thingy) but I've been having some troubles with it.I've been using this script :

var jumpSpeed: float = 3.5;
var distToGround: float;

function Start(){
// get the distance to ground
distToGround = collider.bounds.extents.y;
}

function IsGrounded(): boolean {
return Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.1);
}

function Update () {

// Move the object to the right relative to the camera 1 unit/second.
transform.Translate(Vector3.forward * Time.deltaTime);

if (Input.anyKeyDown && IsGrounded()){
rigidbody.velocity.x = jumpSpeed;

}
}

And this is the result (which is not what I want) :

https://www.youtube.com/watch?v=Fj8B6eI4dbE&feature=youtu.be

Anyone has any idea how to do this ? Im new in unity and scripting.Im using java btw.

Ty.

© Game Development or respective owner

Related posts about android

Related posts about unity