As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/
Options

Let's [Game Design/Development]

123468

Posts

  • Options
    DrDinosaurDrDinosaur Registered User regular
    T4CT wrote: »
    Best way to instantiate a game object as a child of an existing gameobject in a scene mid-run, but then also have that game object's transform be set in relation to its parent and MOVE with its parent?

    (I need a popup over someone's head when X happens that lasts until the person disappears off screen. Every way I've tried either doesn't properly child the co-ordinates of the popup, so it ends up being placed weird, or throws me a null exception for various reasons)

    http://docs.unity3d.com/ScriptReference/Transform.SetParent.html
    child_transform.SetParent(parent_transform). Once it's set as the child, moving the parent should automatically move the child. If not, write a move method that first updates the parent's transform, then set up a foreach loop that goes through each attached transform and modifies them.

  • Options
    Speed RacerSpeed Racer Scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratchRegistered User regular
    edited May 2015
    Oh there's a set parent method

    Here ive just been doing

    child.transform.parent = parent.transform;

    Anyway once an object is a child, it will always move, scale, and rotate the exact same way as its parent, and it's coordinates will be redefined so that whatever the parent's location is is (0,0,0)

    So if you're doing a 2d game, what you're looking for would look something like

    GameObject child = (GameObejct)Instantiate(child); //Instantiate the child

    child.transform.SetParent(parent.transform, true); //make it the child of the parent

    child.transform.localPosition = Vector3.zero; //move it to the parent

    child.transform.translate(new Vector3 (0, parent.renderer.bounds.size.y, 0)) //this will move it up by an amount equal to the height of the parent

    There's probably better ways to do that last line depending on what exactly you need

    Speed Racer on
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    i programmed staircases.... aka portals to other maps over the weekend

    and... it worked the first time! no crazy bugs. I was expecting my assumptions about object deallocation to be false and I would get stuff like enemies from the previous map still hanging around and attacking me or stuff like that but nope.. completely clean transitions

    i am the C++ lord

  • Options
    T4CTT4CT BAFTA-NOMINATED NAFTA-APPROVEDRegistered User regular
    Oh there's a set parent method

    Here ive just been doing

    child.transform.parent = parent.transform;

    Anyway once an object is a child, it will always move, scale, and rotate the exact same way as its parent, and it's coordinates will be redefined so that whatever the parent's location is is (0,0,0)

    So if you're doing a 2d game, what you're looking for would look something like

    GameObject child = (GameObejct)Instantiate(child); //Instantiate the child

    child.transform.SetParent(parent.transform, true); //make it the child of the parent

    child.transform.localPosition = Vector3.zero; //move it to the parent

    child.transform.translate(new Vector3 (0, parent.renderer.bounds.size.y, 0)) //this will move it up by an amount equal to the height of the parent

    There's probably better ways to do that last line depending on what exactly you need

    yesssssss

  • Options
    Speed RacerSpeed Racer Scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratchRegistered User regular
    man

    designing stuff is hard

  • Options
    Speed RacerSpeed Racer Scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratchRegistered User regular
    at least with programming you're working toward a very specific target

    and okay sometimes it's a moving target but at least you have a clear idea in mind for what your shit should do

    designin' though is just

    "come up with some ideas and hope they're good because you won't know for sure one way or the other until you put a ton of work in to put them into a testable state"

  • Options
    MachwingMachwing It looks like a harmless old computer, doesn't it? Left in this cave to rot ... or to flower!Registered User regular
    I had a phone interview with a pretty big company today

    a snowy company, that knows something about the craft of war

    and star

    and...watching....over????

    THE INTERVIEW WENT PRETTY WELL I THINK

    l3icwZV.png
  • Options
    Speed RacerSpeed Racer Scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratchRegistered User regular
    edited May 2015
    Every now and then I tell myself

    "The only listed requirement I don't meet to be a hearthstone designer is having legendary rank, why don't I just get ass deep into hearthstone and hit legendary and apply..."

    Speed Racer on
  • Options
    AnzekayAnzekay Registered User regular
    at least with programming you're working toward a very specific target

    and okay sometimes it's a moving target but at least you have a clear idea in mind for what your shit should do

    designin' though is just

    "come up with some ideas and hope they're good because you won't know for sure one way or the other until you put a ton of work in to put them into a testable state"

    I am basically the opposite of this. Programming and development stuff is pretty tough for me and I've never really been able to get a solid grasp on code.

    But designing stuff? Testing ideas, developing ways to mesh systems and themes? I'm all over that stuff.

  • Options
    Speed RacerSpeed Racer Scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratchRegistered User regular
    alright so here's a dumb question

    i'm trying to figure out how make a sword swing work in a top down zelda clone

    so far, i know that as you swing the sword, you want to have a hitbox that more or less occupies the same space as the sword on each frame (possibly adjusted slightly for gamefeel purposes)

    and if the sword's hitbox contacts an enemy, you want to do some damage function with that enemy

    but where I'm getting tripped up is, what's the best way to determine whether there is an enemy in the path of the sword

    the most obvious solution would be to raycast from the hitbox in the direction of the sword's arc, but it seems like you'd have to do a lot of ray casting each frame to ensure that you're not missing anything. False negatives seem like they need to be the number one thing to avoid at all costs for this sort of thing, and raycasts in this sort of environment seem prone to lead to false negatives

    the only other solution I can think of though, is to maintain some sort of array or linked list or some other data structure, containing references to every enemy currently spawned, and on every frame of the sword swing, a script iterates through that list and checks each enemy's hurtbox to see if it overlaps with the sword's hitbox. That's guaranteed to always produce the correct answer, but it seems like a very slow and inefficient approach, especially in potential situations where there could be a large number of enemies.

    I suppose another option would be to have that sort of data structure, and as enemies move, they check the player character's position to see whether or not they're within attack distance, and if they are they add themselves to the list and if they're not they remove themselves from it. That's better in the sense that it would keep the number of checks performed low, but it still seems like there's gotta be a smarter, simpler solution that I'm just not thinking of.

  • Options
    Speed RacerSpeed Racer Scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratchRegistered User regular
    Basically I assume that if they could pull it off on a snes then there must be a very simple, very elegant solution to the problem

    Another idea would be to work it into the tile system used for collision detection

    Have each tile have a "hasEnemy" Boolean, along with a Boolean to reference enemies. When an enemy moves into a tile it sets the tile's Boolean to true and assigns itself to the variable, and when it exits the tile it sets the Boolean to false and sets the variable to null

    If the sword passes through a tile where "hasEnemy" is true then it performs the sword hit function on the referenced object

    that seems like a solid way of doing things

  • Options
    Speed RacerSpeed Racer Scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratchRegistered User regular
    Ahhhh but wait

    Unless I did a tile system where the tiles were 1 pixel in size, it's possible to straddle tiles and not fully occupy them

    Which would make that system produce false positives

    Which are better than false negatives but still bad!

  • Options
    MachwingMachwing It looks like a harmless old computer, doesn't it? Left in this cave to rot ... or to flower!Registered User regular
    Collision detection between primitives is actually surprisingly cheap, thanks to Minkowski addition! Unless you're doing per-poly collision, you don't really need to worry about the cost of checking against a bunch of enemies. I don't know if Unity uses anything like octrees to optimize these kinds of checks by default, but if not then that'd save some computational time as well.

    l3icwZV.png
  • Options
    agoajagoaj Top Tier One FearRegistered User regular
    For large numebrs of enemies you'd use a quadtree(or octree for 3D). Quadtree divides up space into 4 sectors, and those each have 4 sectors, and those etc.. to some depth. Whenever an enemy moves you'd find which sector it best fits. If it overlaps a border it will be listed in the parent node, otherwise it's placed in the child node. This can be made more efficient by dynamically splitting sectors where enemies are focusing and removing nodes where there are few.
    So now you take your hurtbox and find the node it fits into and check for collision for anything listed on that whole branch.
    http://www.mikechambers.com/blog/2011/03/21/javascript-quadtree-implementation/

    But if this is in unity, just use their collision system.

    ujav5b9gwj1s.png
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited May 2015
    going to throw in my two cents here

    I don't think the sword in top-down zeldas does per-pixel collision sampling. At least not on the SNES. It's relatively expensive to do that, and the difference between that and just some abstract collision maps is going to be almost imperceptible. There's fairly good evidence that LTTP relied on low-resolution collision maps that were just Done Really Well to give the perception of high resolution collision.

    first and foremost you'll want to cull down your potential target list to just the enemies that are within the hypothetical reach of Link, facing in any direction, which is simple

    then define a rectangle that specifies the hit box for the sword at a given point in the swing... if the swing is a 6 frame animation, then it can have 3 stages each occupying two frames... one with the sword extending from his body, one straight forward, and then one out to the side and returning

    then do your hit testing, done

    Jasconius on
  • Options
    Speed RacerSpeed Racer Scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratchRegistered User regular
    edited May 2015
    edit whoops didn't mean to hit post

    Speed Racer on
  • Options
    Speed RacerSpeed Racer Scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratchRegistered User regular
    agoaj wrote: »
    But if this is in unity, just use their collision system.

    i remember being incredibly frustrated by unity's stuff early on and that's why i decided to just go it on my own, and now i'm going back and trying to use their stuff and i'm still finding it to be nothing but a headache machine

    for instance: based on the evidence I've gathered first hand I think the idea that the OnCollisionEnter() function is called when a collider collides with another is in fact a myth

  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited May 2015
    Unity is insidious in that you end up learning how to use Unity but not learning how to program, because just operating within Unity's environment is a language unto itself. That headache is your brain telling you there are so many better ways to do such simple tasks

    most 3D engines are like this

    i've been programming professionally at a high level for almost ten years. i open up unreal editor and its all like nope.avi

    Jasconius on
  • Options
    Speed RacerSpeed Racer Scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratchRegistered User regular
    yeah that's part of it

    if i know how a thing works i know how to tweak it

    unity keeps so much stuff under the hood so that non-programmers can figure it out that it just becomes a chore when something doesn't work how i expect or want it to

    although with that said

    the animation stuff is really great and i love it

  • Options
    Speed RacerSpeed Racer Scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratchRegistered User regular
    edited May 2015
    doing more research LTTP apparently does occasionally produce false negatives with the collision on link's sword swings, so determining how it does it and copying it seems like a bad idea

    right now i'm thinking the solution is

    when the player does the sword input, generate a list of every enemy that might be hit by the sword:
    -Take a list of all enemies on screen
    -Add all enemies within the range of the sword to the list of potential targets
    -for the remaining enemies, check their movement speed, and see if it's possible for them to move into the path of the sword in the time the sword swing animation takes to complete. if it does, add them to the list of potential targets

    once that's done, on each frame of the sword swing, determine whether the sword's hitbox is overlapping each potential target's hurtbox, and if in any case it is, call that enemy's damage function and remove that enemy from the list of potential targets, to ensure that it's impossible to hit the same enemy twice in one swing

    Speed Racer on
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    well anything done on a 16-bit system with mere kilobytes of RAM will produce "false negatives" to the human eye, no doubt. but sometimes its about effort level too. pixel-testing can be rough

  • Options
    Speed RacerSpeed Racer Scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratchRegistered User regular
    one function that seems like it'd be super useful to have in unity is something where like, you pass it a rectangular prism as an argument, it looks at the space defined by that rectange in the coordinate plane, and it returns a data structure, probably a list?, of every object contained within that space

    which

    i guess what i'm really asking for is a 3 dimensional equivalent to raycasting

    and i can see why that would get costly, enough that even though it's the intuitive way to solve a lot of problems it's not the optimal way

  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited May 2015
    that's a common thing to do though in games

    the way some developers solve that is by constantly keeping up list of objects in given quadrants, so that when you go to sample an intersect on a prism, you're only iterating through objects likely to be a match, instead of every object in the game

    you can also categorize your collide-able objects, so like "this object can collide with players" vs "this object can collide with walls but will pass through players"

    its all about culling your data down to a point where you can cheaply iterate through it

    conversely, in an engine as refined as Unity, it probably wont matter if you cull or not until you get to thousands of objects in a scene, maybe even tens of thousands

    Jasconius on
  • Options
    MachwingMachwing It looks like a harmless old computer, doesn't it? Left in this cave to rot ... or to flower!Registered User regular
    edited May 2015
    -for the remaining enemies, check their movement speed, and see if it's possible for them to move into the path of the sword in the time the sword swing animation takes to complete. if it does, add them to the list of potential targets

    This'll probably be more expensive than just checking a wider area to begin with. If you know the fastest an enemy is ever gonna move, you can fudge that first area check outward to compensate.

    i guess what i'm really asking for is a 3 dimensional equivalent to raycasting

    and i can see why that would get costly, enough that even though it's the intuitive way to solve a lot of problems it's not the optimal way

    Unity has a form of "thick" raycasting (spherecasting). Alternatively, you could do a few raycasts at the extemes of your sword.

    I spent a bit of time last year prototyping a game where the character's gravity oriented itself to whatever surface he was touching. One problem I ran into was how to handle "curved" surfaces and stepping across angled polygons- I ended up doing 5 raycasts (one at each corner of the player's bounding box downward, one at the center), looked at the normals of each surface hit, and averaged the hits to get the final orientation.

    Machwing on
    l3icwZV.png
  • Options
    HellaJeffHellaJeff FAB FRESH RAIIINBOOWWWWWRegistered User regular
    Is anyone in here doing stuff in c++? I want to start messing with GUIs, but I haven't ever setup an external library, or built a GUI anything

  • Options
    Speed RacerSpeed Racer Scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratchRegistered User regular
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    HellaJeff wrote: »
    Is anyone in here doing stuff in c++? I want to start messing with GUIs, but I haven't ever setup an external library, or built a GUI anything

    Yes. I think the most hobo-efficient way right now is to use Awesomium, which runs a chrome window html gui and will feed you textures to send to the frame buffer.

  • Options
    Speed RacerSpeed Racer Scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratchRegistered User regular
    edited May 2015
    alright this is an issue i've been struggling with forever now

    the art assets i'm using are pixely lookin

    and no matter what i do

    i can't make them appear correctly when i build and run the game

    as a random example my player character sprite is 18x25

    when i import it to unity, i have it treat 1 pixel as 1 world unit, meaning its 18 units by 25 units tall

    and i use point filtering so there's no bluriness

    and i've gone to great lengths to always ensure that everything's coordinates are integer values (for instance i spent most of today reworking my movement system so that you could use decimal speed values and still get integer movement, for example a character with .5 speed will just move one whole unit every 2 frames)

    I'm using an orthographic camera, with a size of 112.5, for a camera view that encompasses 400 x 225 world units, which is exactly 1/4 of 1600x900

    and yet when I build the game and run it at a 16:9 aspect ratio at 1600 by 900 resolution

    I get weird little goofs

    things like some columns of "pixels" on a sprite being wider or narrower than other columns

    or i think i've mentioned this here before, if I crank the graphics quality up all the way some of the sprites get red or grey boxes around them that denote the borders of the sprite, which I'm given to understand represent some sort of rounding error when calculating the position of an object, but there shouldn't BE any rounding error because everythings coordinates should be integer values!

    This is a cropped screenshot I took of my game while it was running at full screen at 1600x900, with my monitor set to the same resolution:

    6wYC2EV.png

    You can see what I'm talking about by looking at the area around her left eye and above.Most of the sprite scaled perfectly by a factor of 4, but a little piece of it there didn't, and in other places it' been more noticeable

    The weird thing is that the errors are consistent. Like every single time I build and run the game that sprite will look exactly like that, but only that instance of that sprite. I have another object in the scene with the same exact sprite, but it has a different set of graphical errors. If I edit that sprite and reimport it, there's a reasonable chance that the specific error it has will go away but a new one will appear (the last draft of this sprite had a misshapen pupil in one of her eyes)

    what the hell is going on and how can I stop it

    Speed Racer on
  • Options
    Speed RacerSpeed Racer Scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratchRegistered User regular
    edited May 2015
    I also tried just scaling up the sprites by four and expanding the camera, so that ostensibly there wouldn't be any need for scaling and no chance of things being messed up by scaling

    But if anything that made it worse

    Speed Racer on
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    have you tried rounding your sprites X/Y coordinates to whole numbers?

  • Options
    Speed RacerSpeed Racer Scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratchRegistered User regular
    That's what I was saying, they're never not whole numbers

  • Options
    Speed RacerSpeed Racer Scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratchRegistered User regular
    edited May 2015
    just for shits and giggles though I added this code to the object:
    void Update () {
    		if (transform.localPosition.x % 1 != 0){
    			transform.localPosition = new Vector3(Mathf.Round(transform.localPosition.x), transform.localPosition.y, transform.localPosition.z);
    		}
    		if (transform.localPosition.y % 1 != 0){
    			transform.localPosition = new Vector3 (transform.localPosition.x, Mathf.Round(transform.localPosition.y), transform.localPosition.z);
    		}
    	}
    

    Didn't do anything.

    Speed Racer on
  • Options
    MachwingMachwing It looks like a harmless old computer, doesn't it? Left in this cave to rot ... or to flower!Registered User regular
    Did you try locking the camera's position to whole numbers?

    Did...did you lock your computer chair to whole numbers

    l3icwZV.png
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    Replace all keys on keyboard with whole numbers

  • Options
    T4CTT4CT BAFTA-NOMINATED NAFTA-APPROVEDRegistered User regular
    luke are you whole numbers?

  • Options
    Speed RacerSpeed Racer Scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratchRegistered User regular
    edited May 2015
    The camera is also locked to whole numbers and so am I

    Everything is whole numbers

    Except for the way the sprite is drawn in the screen

    i guess no one has any ideas on why this thing is shitting itself then? :(

    Speed Racer on
  • Options
    DarricDarric Santa MonicaRegistered User regular
    Re: The physics discussion on the last page, here's a really good talk from GDC about 2D physics from the QWOP guy:

    http://www.gdcvault.com/play/1021921/Designing-with-Physics-Bend-the

  • Options
    T4CTT4CT BAFTA-NOMINATED NAFTA-APPROVEDRegistered User regular
    The camera is also locked to whole numbers and so am I

    Everything is whole numbers

    Except for the way the sprite is drawn in the screen

    i guess no one has any ideas on why this thing is shitting itself then? :(

    the only help I can offer is that I had a similar problem in Unity, and upon compiling and running outside of the editor NONE of that stuff happened

  • Options
    Speed RacerSpeed Racer Scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratchRegistered User regular
    this IS being compiled and run outside the editor

    I guess i'll go ask the question on Unity Answers, see if they have any ideas

  • Options
    Speed RacerSpeed Racer Scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratch scritch scratchRegistered User regular
    wait wait wait wait wait wait wait

    the camera ISN'T at a whole number coordinate, it's the only thing that isn't

    I wanted its lower left corner to be at (0,0)

    and since its orthographic size is 112.5, that puts its coordinate position at (200,112.5)

    could this be the answer to my problems?!?!?!?!?!!? let's find out

Sign In or Register to comment.