- Home /
A spinning char problem
Hi everyone, I got a little problem with my current game... When I press the move buttons, my char doesnt move, but for that, its like he makes spins the World around and himself is allways in the middle... (Sorry for my bad english, I am an Austrian one ^^) How ever, maybe someone can help me, heres the script.
#pragma strict
public var JumpHeight = 0;
public var moveSpeed = 0;
public var maxJumps = 0;
private var numJumps = 0;
function Start () {
}
function Update () {
var x;
var y;
if(Input.GetKeyDown(KeyCode.Space) && CanJump()) {
x = GetComponent(Rigidbody).velocity.x;
GetComponent(Rigidbody).velocity = new Vector2(0, JumpHeight);
++numJumps;
}
if (Input.GetKey (KeyCode.A)) {
y = GetComponent(Rigidbody).velocity.y;
GetComponent(Rigidbody).velocity = new Vector2(-moveSpeed, y);
}
if (Input.GetKeyDown (KeyCode.D)) {
y = GetComponent(Rigidbody).velocity.x;
GetComponent(Rigidbody).velocity = new Vector2(moveSpeed, y);
}
}
function OnCollisionEnter (coll : Collision) {
if (coll.gameObject.CompareTag("Ground")) {
numJumps = 0;
}
}
function CanJump() {
return numJumps < maxJumps;
}
and here is an Image:
Any help would be VERY great :)
I am not sure whether I understand you, but would this work for you?
#pragma strict
public var JumpHeight = 0;
public var moveSpeed = 0;
public var maxJumps = 0;
private var numJumps = 0;
function Start () {
}
function Update () {
var x;
var y;
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space) && CanJump()) {
x = GetComponent(Rigidbody).velocity.x;
GetComponent(Rigidbody).velocity = new Vector2(0, JumpHeight);
++numJumps;
}
if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.A)) {
transform.position.x -= moveSpeed * Time.deltaTime;
}
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.D)) {
transform.position.x += moveSpeed * Time.deltaTime;
}
}
function OnCollisionEnter (coll : Collision) {
if (coll.gameObject.CompareTag("Ground")) {
numJumps = 0;
}
}
function CanJump() {
return numJumps < maxJumps;
}
lol, that was very helpfull =) !! It just worked fine :D But now there is another problem... The ground you see on the picture is a 3D cube, I can move arround just fine, but when i get to the corned of the " Planet " the same is happening again... With the spinning in air I mean :/ Some kind of Gravity system could be nice :O
I am not sure whether using rigidbody is a wise choice. Rigidbody simulates realistic physics, but that is not something you want. $$anonymous$$aybe you should use Character Controller ins$$anonymous$$d. And use controller.$$anonymous$$ove() method to move your character. And using .isGrounded check whether your character is, well, grounded. If not, use $$anonymous$$ove() method with Vector.down parameter to make it fall without spinning.
Your answer
Follow this Question
Related Questions
Get position of the centre of each grid tile 1 Answer
MMORPG Scripting Ideas 1 Answer
Defining a local spawn offset 1 Answer
Rotating world/player 1 Answer
[C#|JS] GPS Routes? 1 Answer