Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Mike's big topic o' questions!

Discussion in 'Editor & General Support' started by MikeC, Jul 17, 2006.

  1. MikeC


    Jul 15, 2006
    Hi there!

    I've had a Unity trial going for a while but as the only access I have to decent spec macs is at work I've barely used it. However I'm finally getting some vacation time so I'm gonna spend some actual time on making a game. I've already modelled and animated most of the assets in Maya and imported them in. I've scoured through the documentation and I'll be going through all the tutorials next week but as my game is more of a platformer type game, there's still some things I'm unsure of so if anyone can give me a hand it would be appreciated! I'll even give you special mention in the credits (That's if I can figure out how to make credits... ;) ) The game's not a commercial thing though. It's more for fun and learning (And something cool to put in the portfolio) than anything. As it's my first game, I'm remaking the first level from Sonic the Hedgehog, but in 3D!

    Anyway, to the questions:

    I've got my main character and his controls mostly set up, (run and jump: the easy stuff) however there's a few more I'd like to add in.

    1) I've got a waiting animation that I'd like to play if the controls aren't touched for 20 seconds or so. How would I add that in?

    2) When he jumps, I want to add in a "double jump" feature in which when the jump button is pressed twice in rapid succession, the character (while still in jump animation) will hone in on any collision objects within a set distance. I also need this to be repeatable so if there's a row of 5 collision objects, after the character has hit the first one, the player needs to be able to press the jump button again to make him hone in on the second object and so on...

    3) Collision objects! I've tried to figure these out but it's just not clicked for me yet. I've got a bunch of different collision objects. I've got the golden rings which the character collects, when those are touched they need to vanish and be added to the total in the gui (The GUI's a whole other section but I've not fully looked into Unity's GUI system yet so I'll refrain from asking questions on that until I've looked into it and am still none the wiser ;) ) Another collision object would be the enemies, which explode on collision. However, they only explode if the character is in the jump animation, if the character collides with it whilst running or walking he'll get hurt. The next collision object is a spring that will launch the character up in the air and the last one is a marker that will trigger the end of the level and bring up the end of level dialogue (again, GUI stuff that'll wait for later).

    4) loop-de-loops and stuff. It's not Sonic without a running round a loop! I've played about with the character control settings but I can't get him to run all the way around the loop. My guess is it's something to do with giving the loop it's own gravity or something but I'm not certain.

    5) I'm currently using the supermariocamera script on my Main Camera, however the camera is forever behind my character. I'd like the camera to be looking at the character from the right (Like in a 2D platformer type game). I've spent a lot of time messing with the camera settings but I can not figure out how to get the camera to do that! At a couple of points in the level however, I need the camera to come behind the character to get a better viewpoint, is this possible?

    6) Oh, also, I'd like to have an invisible barrier at the far side of each platform to stop the character from falling off too easily. Can I make these in Maya and just add a transparant material to them or is it best to do them in Unity?

    Right, I think that's enough rabid typing from me, lol! If anyone can please help me with this I'd be really very grateful!

    Thanks in advance! :)
  2. Morgan


    May 21, 2006
    Welcome! I'm certain that's all doable, but I hesitate to give halfway answers since I'm still new myself :)

    But I can think how you might do the loops:

    * Keep track of the vector (normalized) that points from the center of the loop (an empty GameObject or else just the coordinates of the loop's mesh center).

    * Change gravity to that direction:

    Code (csharp):
    2. Physics.gravity = ThatVector * YourGravityStrength;
    Sounds like a fun project--keep us posted! And let us play :)
  3. aaronsullivan


    Nov 10, 2005
    MikeC, just wanted to suggest that you'd do much better to separate each of these questions into a different topic. Take it one question at a time. :) I don't personally have time to sift through all that, but if it was just one of those, I'd probably have something to share. :D
  4. NicholasFrancis


    Apr 8, 2005
    I'll get you started on one before I go to bed:

    Unity basically has 2 collision types: Meshes primitives. primitives can collide with meshes and each other, but collision between 2 meshes is not detected. You typically use meshes for your level geometry, and primitives for everything else.

    You add a collision primitive to a GameObject by doing Component->Physics->Box Collider from the main menu. (or sphere or whatever)

    Collision primitives have 2 basic modes of opertaion: Colliders and Triggers. Colliders are solid objects, triggers are not. They send out messages to any scripts attached to them.

    Take the ring and add a SphereCollider to it, then create a script that goes something like this (Assets->Create->JavaScript)

    Code (csharp):
    2. function OnTriggerEnter () {
    3.     Debug.Log ("Got a Ring");
    4.     Destroy (gameObject);
    5. }
    Now drag this script on to your ring.

    This will give you a debug message remove the ring when anything physical touches it (player, enemy, whatever). For now, that's ok.

    The OnTriggerEvent function can have a parameter, which is the other object collided with. Using this you can check if it's the player (does the collided object have a Player script attached?). If so, is he jumping, if so, kill me, etc...

    Again: Use OnTriggerEnter, and if it's the player tell him to shoot upwards. It's up to your player to go there ;-)

    You'll figure it out ;-)

    Edit: Once you've attached, say, a Sphere Collider to a gameObject, you'll see a small question mark in the right of it's heading. That's the quickest way to context-help for that component. It's your friend.
  5. elias723


    Feb 10, 2006
    1. For the waiting, just add to the script in which it controls his other animations. You will need a variable to count seconds since he last moved, and and thing to say "if this gets above a certain point and he is still not moving, play the waiting animation." When he moves again, you need to reset the counting variable to 0.

    2. The double jump isn't too hard - do something similar to the variable for counting time thing. If the button is pressed again within .1 seconds, make him jump again. The other thing - go to the nearest jump-point, is a little tougher. It involves saying "if the thing is within this distance and I'm double jumping, move me at it." I'll leave the coding to you though, since I don't like mind benders unless they're my problem.

    3. already answered

    4. Perhaps you could just add more speed to Sonic to get him around? Tough to say how that could work. Good luck!

    5. For the camera, to get it to go from the side, just drag the camera (in the Inspector) onto the character, remove all the scripts from the camera, and move/rotate the camera until it looks at the character from far enough away. You could change the position/rotation of the camera in a script - say - if you press "c," move the camera to behind Sonic and turn it towards him. Fairly basic, but you could do lots of other things to make it cooler if you wanted.

    6. To do the invisible barrier, you could just make two empties (GameObject > Create Empty) and add box colliders to them. Put the empties on either side of the level, and then make the box colliders really really long and tall so that they cover the entire "wall" area you need. You could also do the thing you were talking about in Maya.