My game is in Javascript. My gravity is normally -9.81 in the Y. My jumpheight is normally 9.
I’ve successfully flipped the gravity when my player/ball touches a special capsule. Unfortunately, I can’t get the ball to jump in the opposite direction: down while I’m on the ceiling.
I have been able to change the jump height when I touch other special capsules that grow and shrink the ball (namely make the ball jump higher or lower) but I can’t seem to do the above opposite jump.
Here’s my code. Any ideas what I’m doing wrong? I’ve tried different jumpheight values.
#pragma strict
var player : GameObject;
var gravityChangeSfx : AudioClip;
var gravityC = Vector3 (0, 9.81, 0);
function Awake() {
//player = GameObject.Find("Ball").GetComponent.<Rigidbody>();
player = GameObject.Find("Ball");
Debug.Log("GravityUpsideDown script - first Find Player/Ball");
}
function OnTriggerEnter (col : Collider) {
//Trigger if only the player touched the object
//GameObject.Find("Player");
if (col.tag == "Player") {
Debug.Log ("GravityUpsideDown script - ball collided with this Box");
// Change Gravity
Physics.gravity = gravityC;
//Make ball jumpheight the opposite
BallControl.jumpHeight = -9;
Debug.Log("GravityUpsideDown script - jumpHeight made upsidedown");
GetComponent.<AudioSource>().pitch = 1;
GetComponent.<AudioSource>().clip = gravityChangeSfx;
GetComponent.<AudioSource>().Play();
Debug.Log("GravityUpsdieDown script - gravity upside down");
}
}
And here’s my ball control code associated with the player ball:
function Update ()
{
//Handle ball rotation.
var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
rotation *= Time.deltaTime;
GetComponent.<Rigidbody>().AddRelativeTorque (Vector3.back * rotation);
//Handle ball jump
if (Input.GetKeyDown(KeyCode.W) && IsGrounded ())
{
GetComponent.<Rigidbody>().velocity.y = jumpHeight;
}
}
function IsGrounded () : boolean { //Check if we're on the ground, return True if we are, else return Null.
return Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.1);
}
I thought the problem had to do with the “&& IsGrounded ()” so I commented that out but it still didn’t work.
TIA
Yeah I can't use it "Unknown Identifier "parent"" Is there another way?
– kasquerGetting this error using that: http://image.prntscr.com/image/437e04d5f7004f89a604b9078cf63671.jpeg
– kasquer