Unity general questions

Comments

  • edited
    While @dislekcia's totally right above, it sounds like we're dealing with a 2D game here, where the benefits of quaternions and their lack of susceptibility to gimbal lock is not a necessary or required property, then I don't think there's anything wrong with thinking in angles of rotation around your camera forward axis, especially not if it makes everything easier to understand. So with that, I don't see anything particular wrong with using Quaternion.Euler, and it's likely a cause for fewer errors than having to think in terms of maths you don't understand.

    That aside, they really aren't that complicated, no! They are basically a point on a 4d sphere, which is a way to represent a rotation between two directions in a similar way to how a matrix can represent a transformation.

    The issue you're having could be down to a number of factors, including a confusion between which vectors you should be using. Previewing these in the unity editor is useful, and remember the differences between local and world space/rotation (red is the x axis, green is y, blue is z. rgb=xyz). If you're rotating things around their forward axis, you're changing the direction their up and right axes will face. The default rotation of your sprite represents how exactly you need to get a thing to face the correct direction. I strongly recommend you have your prefabs/sprites oriented either that they point towards your up axis, or your forward axis, just for ease of use. Forward is preferable for 3D games, but it can unnecessarily complicate things in 2D, in which case you might prefer up.
    Thanked by 2AngryMoose mattbenic
  • hi guys

    Ive been using gamemaker for a while and i want to know when must i use unity because still dont understand whats going on in unity
  • I worked only in gamemaker for about a year, my first real dive into Unity was around April last year during Ludum Dare.

    When should you move to Unity?
    When you understand gamemaker enough to know that there's something you want to do that you can't do in gamemaker.

    Tools are only tools. Use whatever you like and are comfortable with. There are MANY people who make games commercially with gamemaker exclusively - there's no reason to abandon it if you don't feel that you need to.
    Thanked by 1mattbenic
  • Hey guys....... I have no knowledge of coding at all, and I have no 3d studio.... How can I make a first person shooter with unity?.......Maybe some coding tutotials?
  • @Mike16y check out www.cooking with unity.com they have a physics puzzler series (fps style like portal) as well as a FPS series of tutorials. All art is done in unity and he explains the code somewhat as he works through it.
  • Hi Guys,

    Need some help with a silly problem. I have a round gameobject (2d sprite of a planet). I currently have 2 BoxCollider2Ds attached to it. One to the top half and One to the bottom half. They are set up as triggers. When the player enters the trigger's they affect the gravity of the player. The top one pulling the player down, and the other pushing the player up. I got this working the way I want...sort of...well I would prefer if I had 2 CircleCorllider2Ds..or half circles. Any ideas. Here is a pic to better explain what I want:

    image
  • I'm guessing this is the closest you'll get to that:

    http://docs.unity3d.com/ScriptReference/PolygonCollider2D.html

    Do you actually need them to be circular? Would the two boxes not be good enough?

    I don't think there are half circles in colliderland.

    Alternatively, you can detect distance from the centre to any object, then decide if it's above or below simply enough with just the y co-cordinate.
    Thanked by 3FanieG garethf Chippit
  • @Tuism thanks for the prompt response. YES!!!! I can edit the Polygon one to suit my needs. Knew I was missing some obivious solution. Just also saw effectors too. Guess that could be another solution.
  • Hey guys

    I'm making a series of Unity stuff that will open each other, so call them A, B and C.

    For example:
    Player is in A, and presses [3], it'll open C.
    Player is in A, and presses [2], it'll open B.
    Player is in A, and presses [1], it won't do anything.

    I'm using this code to open stuff (in Windows). This opens a file that's in the same folder as the original game.

    Process process = new Process();
    		process.StartInfo.FileName = Application.dataPath + "/../" + "1pgame.exe";
    		process.Start();
    		process.WaitForExit();


    The question I have is - when I make A open B and make B open A again, it launches a separate instance of the game, and since the original game doesn't close, you end up with duplicate instances of games.

    How do you:
    1. Close the current game then launch another game, so that there won't ever be more than one thing running at a time? Or
    2. How do you make it more like an alt-tab to a different game rather than open another instance of the game? (I've checked out Force Single Instance in build options, but it seems to only make any subsequent launches fail, instead of giving the old game focus and switching to it. Or
    3. Any other ideas?

    Richard wrote the wrapper for the AMAZE little mini arcade that ran their bunch of games, which gave me this idea. Not sure if they had this same problem though.
  • edited
    Really not my speciality, but this is what my Google-fu returned:
    http://stackoverflow.com/questions/7357675/how-can-i-set-the-focus-to-application-which-is-allready-in-running-state

    [DllImport("user32.dll")]
    internal static extern IntPtr SetForegroundWindow(IntPtr hWnd);
    
    [DllImport("user32.dll")]
    internal static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
    ... 
    Process currentProcess = Process.GetCurrentProcess();
    IntPtr hWnd = currentProcess.MainWindowHandle;
    if (hWnd != IntPtr.Zero)
    {
        SetForegroundWindow(hWnd);
        ShowWindow(hWnd, User32.SW_MAXIMIZE);
    }
    Thanked by 1Tuism
  • Thanks @Elyaradine, I tried to understand that but failed :P

    I did however work out a janky solution, I start the new game and immediately quit the current one, and that way there are never old processes lying around.

    Process process = new Process();
    		process.StartInfo.FileName = Application.dataPath + "/../" + "1pgame.exe";
    		process.Start();
    		Application.Quit()


    Seems to work :D
  • General questions strikes back :p

    I have a weird one, or at least I find it weird, dunno where to look...

    I'm using a struct to define a PlayerObject, then passing one of the PlayerObjects into a function. In the function, I can't seem to refer to the PlayerObject and make changes to its functions, but I can refer to an instance of the PlayerObject and change it directly... What am I doing wrong?

    Relevant code:

    public struct PlayerObject
    {
    	public int state;
    }
    
    public class GameController : MonoBehaviour 
    {
    	public PlayerObject P1;
    	
    	etc etc
    
    	void MoveBlocks (PlayerObject _player, Vector2 _direction)
    	{
    		_player.state += 1; // this line doesn't work
    		P1.state += 1; //this line works
    	}
    }


    Of the two lines there in the MoveBlocks function, the first doesn't work, no errors, nothing. The second line works, but I want to pass different PlayerObjects into the function so that it's not always the same PlayerObject.

    What am I missing?
  • Okay I found the answer to my question - according to a Unity answer:
    You cannot modify the values inside a struct returned from another component the way you are - and for good reason. A struct is passed by value.
    http://answers.unity3d.com/questions/425510/cant-modify-struct-variables-c.html

    The way to solve it is to change the struct to a class.
  • Have you tried passing the struct by reference?
    void MoveBlocks (ref PlayerObject _player, Vector2 _direction)
  • critic said:
    Have you tried passing the struct by reference?
    void MoveBlocks (ref PlayerObject _player, Vector2 _direction)
    No, what is this voodoo magic? :)

    Is there any reason to use this rather than changing the struct to a class?
Sign In or Register to comment.