Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Need help with code

Discussion in '2D' started by blastoii, Jan 7, 2015.

  1. blastoii

    blastoii

    Joined:
    Jan 7, 2015
    Posts:
    4
    Greetings everyone,

    I am starting a new game in 2D in unity, but there is something I want to program of which I can't find any help or information about on the internet. Maybe I have not looked good enough, but asking for is never wrong. So hopefully some you could help me.

    There are two things that I have trouble with to program.

    First:
    A object which can be controlled with the mouse by clicking and dragging.
    This object serves as a platform plateau which can move a object on it. Like a transport

    So let's say there is a bal and it's moving to right and it ends upon the platform/plateau, but the ball is still moving to the right.
    With the mouse you drag the platform/plateau to a spot, or destination or anywhere, with the ball still on top of it and the ball is still moving to the right.
    The platform/plateau is not influenced by gravity and it is solid.

    I hope this idea is understandable.

    Second:
    A self moving object. A object that moves to the right and is under influence of gravity. So it falls of ledges.

    I have like a bit more than month to finish this game and if it is really to hard or diffecult than maybe I should think of some else. I am still doing research, still, if you guys or girls know a way or a code, please let me know.

    With regards,

    abragon
     
    Last edited: Jan 7, 2015
  2. Mikenseer

    Mikenseer

    Joined:
    Jul 24, 2012
    Posts:
    72
    The first case seems like a simple case of setting an "Is Kinematic" flag to false on your platform object while also setting up click and drag controls using ray-casts. You'll find many How-To's on that through Unity's site and google.

    The second you could use the same code as a character controller (i.e. 'W' moves forward) but replace the "KeyDown" code with your own trigger(s). Essentially just change the X,Y, and/or Z velocity of your "self moving object" while leaving it Kinematic so it will fall off ledges.

    I suggest you run yourself through a few tutorials and such to better acquaint yourself with Unity, as these are fairly simple concepts. No harm done looking for help!
     
    blastoii likes this.
  3. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    self moving
    add collider2d,rigidbody2d and script like:
    public float speed;
    void Start () {rigidbody2D.velocity = new Vector2 (speed, rigidbody2D.velocity.y);}
     
  4. blastoii

    blastoii

    Joined:
    Jan 7, 2015
    Posts:
    4
    I used 'AddForce' instead of 'Velocity'. I wanted it to be affected by graffity, but thanks.