Sliding movement how ?

how can i do for when the player take the second platformer run and if i jump again come back to the 1 platformer

my code:

using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {

    public float fuerzaSalto = 15f;
    private bool corriendo = false;
    public float velocidad = 1f;

    public float distanceTraveled;

    private bool enSuelo = true;
    public Transform comprobadorSuelo;
    private float comprobadorRadio = 0.07f;
    public LayerMask mascaraSuelo;

    private void GameStart () {
       
        distanceTraveled = 0f;
        GUIManager.SetDistance (distanceTraveled);
    }


    void Start () {

        NotificationCenter.DefaultCenter().AddObserver(this, "PersonajeHaMuerto");

   
    }

    void FixedUpdate(){

    if(corriendo){
        rigidbody2D.velocity = new Vector2(velocidad, rigidbody2D.velocity.y);
    }

        enSuelo = Physics2D.OverlapCircle(comprobadorSuelo.position, comprobadorRadio, mascaraSuelo);

    }
   

    void Update () {

        distanceTraveled = transform.localPosition.x;
        GUIManager.SetDistance(distanceTraveled);
        distanceTraveled = Mathf.Round (distanceTraveled);

        if(Input.GetMouseButtonDown(0)){
            if(corriendo){
                if(enSuelo){
                    rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, fuerzaSalto);
                }
            }else{
                corriendo = true;
                NotificationCenter.DefaultCenter().PostNotification(this, "PersonajeEmpiezaACorrer");

            }
        }
    }
}

How many threads do you plan on creating about the same thing?

if you help me i dont created more… all of this forum help me -.-

There’s a difference between “help you” and “do it for you”. You seem to be asking for the latter - which, as you’ve experienced, won’t net you good results. You’ve asked the same question repeatedly either without posting code or posting code that has nothing to do with what your’e trying to achieve. I recommend doing as many tutorials as you can find - there are great ones in the Learn section of this site - and coming back here to ask specific questions.

1 Like

hel pme

Do you mean you want to do something like this game

yesss

then all you need to do is flip the gravity

change gravity ffrom lets say 1 to-1 wich means use a rigidbody

my code is this:

using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
    public float fuerzaSalto = 15f;
    private bool corriendo = false;
    public float velocidad = 1f;
    public float distanceTraveled;
    private bool enSuelo = true;
    public Transform comprobadorSuelo;
    private float comprobadorRadio = 0.07f;
    public LayerMask mascaraSuelo;
    private void GameStart () {
      
        distanceTraveled = 0f;
        GUIManager.SetDistance (distanceTraveled);
    }
    void Start () {
        NotificationCenter.DefaultCenter().AddObserver(this, "PersonajeHaMuerto");
  
    }
    void FixedUpdate(){
    if(corriendo){
        rigidbody2D.velocity = new Vector2(velocidad, rigidbody2D.velocity.y);
    }
        enSuelo = Physics2D.OverlapCircle(comprobadorSuelo.position, comprobadorRadio, mascaraSuelo);
    }
  
    void Update () {
        distanceTraveled = transform.localPosition.x;
        GUIManager.SetDistance(distanceTraveled);
        distanceTraveled = Mathf.Round (distanceTraveled);
        if(Input.GetMouseButtonDown(0)){
            if(corriendo){
                if(enSuelo){
                    rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, fuerzaSalto);
                }
            }else{
                corriendo = true;
                NotificationCenter.DefaultCenter().PostNotification(this, "PersonajeEmpiezaACorrer");
            }
        }
    }
}

No one cares what your code is. We’ve told you how to do it, no one’s going to write it for you. It’s simple, It’s one line of code! do it yourself.

where can i learn to change the grativityÂż?

here’s the documentation: Unity - Scripting API: Physics.gravity
it shows you how to change the gravity at runtime.

so then you need to change the gravity when your event occurs to flip it. For example if the spacebar is pressed:

if(Input.GetKeyDown (Keycode.Space))
            Physics.gravity = new Vector3(0, your new gravity, 0);

mmm and the player will can run in the second plaftorm ?

u have to rotate the character too that he will land on his feet u can use either rigidbody.rotation or transform.rotation
to acces them the quarternion.euler is something u could check out

:wink: i will check