Creare Videogiochi - Game Developer
Unity 3d Aiuto script - Versione stampabile

+- Creare Videogiochi - Game Developer (https://www.making-videogames.net/giochi)
+-- Forum: Unity3D Italia (https://www.making-videogames.net/giochi/Forum-Unity3D-Italia)
+--- Forum: Richieste di Aiuto per Unity 3D (https://www.making-videogames.net/giochi/Forum-Richieste-di-Aiuto-per-Unity-3D)
+--- Discussione: Unity 3d Aiuto script (/thread-Unity-3d-Aiuto-script)



Unity 3d Aiuto script - kaosmoda - 07-12-2012

Ragazzi รจ da tempo che sto cercando di capire come creare un trampolino,che mi faccia saltare in alto il player.."classico no".
sto crendo un gioco sulla base ti penelope con player relative controller(joistik)
e vorrei creare tipo una foglia,che quando ci salto sopra mi fa schizzare in alto.
Qualcuno a qualche spunto..???
grazie


RE: Unity 3d Aiuto script - Exorcist - 07-12-2012

Codice:
var bounce : boolean = false;

var bounceAmount : float = 10;

var Player : Transform;



function OnCollisionEnter (other : Collision) {

    if(other.gameObject.tag == "Player") {

        bounce = true;

    }

}



function Update () {

    if(bounce) {

Player.rigidbody.velocity.y = 0;    Player.rigidbody.AddForce(0,bounceAmount,0,ForceMode.Impulse);

bounce = false;

    }

}

t detects when the 'Player' (defined by you) enters the objects collider (aka hits it) then sends him into the air. Though this may not be the best way to handle it, it will work until someone with more experienced helps you.


RE: Unity 3d Aiuto script - kaosmoda - 07-12-2012

grazie mille per il tuo aiuto..
io pero non ho un rigidbody nel player...ho un charcter controller.
Funzionera uguale??
o devo cambiare qualcosa..
purtroppo ora non ho il pc con unity per provare.
Tu che ne pensi??


RE: Unity 3d Aiuto script - Exorcist - 07-12-2012

Non so prova, ma eccoti anche con character control
Codice:
var jumpSpeed = 35;
var controller;
var gravity = 20.00;
var isJumping: boolean = false;
var Jump : boolean = false;
private var moveDirection : Vector3 = Vector3.zero;

function Update()
    {
    var controller : CharacterController = GetComponent(CharacterController);
    if (controller.isGrounded)
    {
    isJumping = false;
    }
    if (Jump)
    {
    isJumping = true;
    }
    if (isJumping)
    {
    Jump = false;
    controller.Move(moveDirection * Time.deltaTime);
    }
    moveDirection.y -= gravity * Time.deltaTime;
}
function OnControllerColliderHit(hit:ControllerColliderHit) {

    if (hit.gameObject.tag == "Bounce")
        {
        print("afaf");
       Jump = true;
        moveDirection.y = jumpSpeed;
    }
}



RE: Unity 3d Aiuto script - kaosmoda - 07-12-2012

ti ringrazio...credo che andra benone...
ObbligatoBig Grin


RE: Unity 3d Aiuto script - Exorcist - 07-12-2012

Di NiEnTe.
E' buona fortuna per il tuo progetto.