Page 1 of 3 123 LastLast
Results 1 to 10 of 26
  1. #1
    Join Date
    Sep 2003
    Posts
    100

    Stick to a wall and do a wall jump

    Does anyone know of a tutorial that describes how to have a 3D player in a 3D scene stick to a wall and do a wall jump?

    Sean
    Life is as hard or easy as u think it is, so think "easy" and take it easy to see how easy it becomes for you, that's the magic of a long life with happiness, smile even if it's forced and fake a smile, then see how life will smile to you and how the sun will shine on you.

  2. #2
    Join Date
    Feb 2009
    Posts
    69
    If you have a collider, you could detect when a collision occurs with an object tagged as "wall", and then do your input. If (a button down) gravity = less than normal, so he slides slowly, and then nested inside that if, do if (button b pressed) player.jump()

    That's a pretty quick and dirty, but it should get you bouncing off the walls...

  3. #3
    Join Date
    Sep 2003
    Posts
    100
    Thank you. I will give it a go. You brought up an interesting point. If the player attached to a wall with a tagged "wall" can this also be used for a wall crawling motion, too? Would I do another nested "if" to crawl up?

    Thank you for answering the post, have a great day!

    Sean
    Life is as hard or easy as u think it is, so think "easy" and take it easy to see how easy it becomes for you, that's the magic of a long life with happiness, smile even if it's forced and fake a smile, then see how life will smile to you and how the sun will shine on you.

  4. #4
    Join Date
    Jun 2008
    Location
    Iran / Tehran
    Posts
    285
    sean if we are speaking about unity, yes, when you hit any collider with your player, in case the collider is set to trigger mode (keep in mind that means your player will walk through it!) then it will trigger a call on OnTriggerEnter and when your player exits the volume it triggers OnTriggerExit, a way to solve the problem of player walking through that collider would be to make an empty game object, parent the wall to this game object (so that the wall become a child), add a box collider to this new game object and make that one trigger and keep the main wall normal collider, then you assign the tag to this parent empty game object.
    Now, when you get OnTriggerEnter event fired, it means that the player is on the wall, so you can do all the stuff you want, for example, play different animation, play a special sound, change the way ASWD keys work (W <-- instead of going forward would make the character go up) or instantiate a prefab like a particle system. basically all you would need to do is that on the start of OnTriggerEnter, check if the object is tagged "Wall" or not, then do what ever you need, remember this will be triggered on the wall not the player, but still that method gives you the other collider (in this case the player) and from there you can access it's mecanim controller or any other public aspect of it.
    If you want to learn something, start teaching about it to others, nothing will help you more than that !

  5. #5
    Join Date
    Sep 2003
    Posts
    100
    Cool, thank you, Alirza. Will I turn off the gravity to the player rigid body when the player passes through the trigger collision of the parent game object...so the player does not fall?
    Life is as hard or easy as u think it is, so think "easy" and take it easy to see how easy it becomes for you, that's the magic of a long life with happiness, smile even if it's forced and fake a smile, then see how life will smile to you and how the sun will shine on you.

  6. #6
    Join Date
    Jun 2008
    Location
    Iran / Tehran
    Posts
    285
    it depends on how you are handling the gravity on your character, I never use rigid body's gravity but handle it in code but if you are depending on it then when ever you want to make your character stay in air yes, also when you would go for the swimming, but then you should turn it on again when you are back to normal situations
    If you want to learn something, start teaching about it to others, nothing will help you more than that !

  7. #7
    Join Date
    Sep 2003
    Posts
    100
    Gotcha, I'll turn it off when you enter the trigger and turn it back on after the player leaves the game object trigger.

    Thanks for your advise, css_Maya.
    Life is as hard or easy as u think it is, so think "easy" and take it easy to see how easy it becomes for you, that's the magic of a long life with happiness, smile even if it's forced and fake a smile, then see how life will smile to you and how the sun will shine on you.

  8. #8
    Join Date
    Jun 2008
    Location
    Iran / Tehran
    Posts
    285
    no problem my friend, any time
    If you want to learn something, start teaching about it to others, nothing will help you more than that !

  9. #9
    Join Date
    Nov 2015
    Location
    USA
    Posts
    3
    Thanks

  10. #10
    Join Date
    Sep 2003
    Posts
    100
    Hello CSS_MAYA, you mentioned that you do not use a rigid body for gravity; that you call gravity in code. I'm using the character controller, which does not need a rigid body. How would you turn off the gravity on the character controller? I'm trying to turn off the character controller's gravity when my player enters the trigger of a wall.

    This is the code I'm using:


    protected CharacterController control;

    protected Vector3 move = Vector3.zero;

    public float walkSpeed = 1f;
    public float runSpeed = 5f;
    public float turnSpeed = 90f;
    public float jumpSpeed = 5f;

    protected bool jump;
    protected bool running;

    protected Vector3 gravity = Vector3.zero;

    // Use this for initialization
    public virtual void Start ()
    {
    control = GetComponent<CharacterController>();

    if (!control)
    {
    Debug.LogError("Unit.Start() " + name + "has no CharacterController!");
    enabled = false;
    }
    }

    // Update is called once per frame
    public virtual void Update ()
    {

    // control.SimpleMove (move * moveSpeed);

    if (running)
    move *= runSpeed;
    else
    move *= walkSpeed;

    if (!control.isGrounded)
    {
    gravity += Physics.gravity * Time.deltaTime;
    }
    else
    {

    gravity = Vector3.zero;
    if (jump)
    {
    gravity.y = jumpSpeed;
    jump = false;
    }
    }

    move += gravity;

    control.Move(move * Time.deltaTime);

    }
    Life is as hard or easy as u think it is, so think "easy" and take it easy to see how easy it becomes for you, that's the magic of a long life with happiness, smile even if it's forced and fake a smile, then see how life will smile to you and how the sun will shine on you.

Page 1 of 3 123 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •