Search Unity

2D Game - Collisions, Walls

Discussion in '2D' started by Flatas, Jan 28, 2015.

  1. Flatas

    Flatas

    Joined:
    Jan 28, 2015
    Posts:
    5
    Hello i have 2D game in Unity, there are two walls.. one on right side and one on the left. The player
    Must pass from one side to another just click and a character move on the other side.. on the walls is obstacles..how i can script this?
     
  2. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I think your description is a bit too vague. Tall walls, short walls? How does the player move, jumping over the walls, passing through them? From one side of the right wall to the other side of the right wall?
     
  3. Flatas

    Flatas

    Joined:
    Jan 28, 2015
    Posts:
    5
    I have the background:
    And the player must jumping from right wall to left wall because on the right is some obstacle.. and when is obstacle on left, he must jump to the right

    CAN YOU HELP ME?
     
    Last edited: Jan 30, 2015
  4. Flatas

    Flatas

    Joined:
    Jan 28, 2015
    Posts:
    5
    Do Someone Know how I can script this?
     
  5. Owchzzz

    Owchzzz

    Joined:
    Jan 26, 2015
    Posts:
    13
    Hi,

    I dont think we can quite understand what you would like to achieve.. The instructions are a bit unclear.
     
  6. Flatas

    Flatas

    Joined:
    Jan 28, 2015
    Posts:
    5
    I need script this: When player touch on the screen on mobile, the stickman moves from the right wall to left wall, or from the left wall to right wall.
     
  7. paolo_lionhg

    paolo_lionhg

    Joined:
    Sep 5, 2013
    Posts:
    17
    always assume that the person you are talking to is a child. now, do you think an eight year old could understand your question?

    your background image doesn't really help at all.

    alright, let's take this one step at a time. in order for you to move your character, use transform.Translate. play with that one first.
     
  8. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    do you using physic2d ? If so, make tags LeftWall and RightWall for walls.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Jump : MonoBehaviour {
    5.     bool isLeft;
    6.  
    7.     // Use this for initialization
    8.     void Start () {
    9.  
    10.     }
    11.  
    12.     // Update is called once per frame
    13.     void Update () {
    14.         if ( Input.GetKeyDown (KeyCode.Space) && isLeft)
    15.             rigidbody2D.velocity = new Vector2 (10, 3);
    16.  
    17.         if ( Input.GetKeyDown (KeyCode.Space) && !isLeft)
    18.             rigidbody2D.velocity = new Vector2 (-10, 3);
    19.     }
    20.  
    21.     void OnCollisionEnter2D (Collision2D other) {
    22.         if (other.gameObject.tag == "LeftWall") {
    23.             rigidbody2D.gravityScale = 0;
    24.             rigidbody2D.velocity = new Vector2 (0, 0);
    25.             isLeft = true;
    26.         }
    27.         if (other.gameObject.tag == "RightWall") {
    28.             rigidbody2D.gravityScale = 0;
    29.             rigidbody2D.velocity = new Vector2 (0, 0);
    30.             isLeft = false;
    31.         }
    32.     }
    33.  
    34. }
    35.  
    try to run walls in assets. I dont think its the best way, but its one way :)

    2. you can just animate it animator. And then switch animationen left-right, right-left

    3. or move between two points with lerp
     

    Attached Files:

    Last edited: Jan 31, 2015
  9. Flatas

    Flatas

    Joined:
    Jan 28, 2015
    Posts:
    5
    Maan, sorry for my bad english :)