my player is grounded when jumping on platfroms ,meanning that it has to land on top of a platform for that platform to be hit. i would like to make one of my platforms (only one of them ) to be able to get hit from the bottom by the player and have the player jumping up (Players head has to hit the bottom of the platform).
private var hit : RaycastHit;
// theTransformHit stores a reference to the last transform that the player jumped on so that we can
// destroy it if all the conditions are met to start a jump
private var theTransformHit : Transform;
// we need to make sure we're grounded before starting a new jump
public var grounded : boolean;
function FixedUpdate () {
// always assume we're NOT grounded every step (and expect to be proved wrong by raycasting etc.)
grounded=false;
// check to see if we're on top of a platform - here we cast two rays, one on each side of the player
// LEFT:
if (Physics.Raycast (transform.position- Vector3.up * 0.5 + Vector3.right * 0.5, -Vector3.up, hit, 1, 1<<9)) {
// we found ground, so set our grounded flag to true, so that the player will jump
grounded=true;
if(rigidbody.velocity.y<0){
theTransformHit=hit.transform;
}
}
// RIGHT:
if (Physics.Raycast (transform.position- Vector3.up * 0.5 - Vector3.right * 0.5, -Vector3.up, hit, 1, 1<<9)) {
// we found ground, so set our grounded flag to true, so that the player will jump
grounded=true;
if(rigidbody.velocity.y<0){
theTransformHit=hit.transform;
}
}
// do jumping, if we're on top of a platform
if(jumpEnabled){
if(grounded rigidbody.velocity.y<0){
doJump();
// send a message to the platform to tell it to destroy itself
theTransformHit.gameObject.SendMessage("hitPlatform");
}
}