Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Polio Vax Scene
Apr 5, 2009



KillHour posted:

Ray casts really aren't that resource heavy in and of themselves. You can probably do a hundred per frame no problem.

To expand on this as well, you can create an invisible greatly simplified mesh that you use specifically for checking vision. A model with a bunch of surface deformations or edges can be reduced massively if all its going to be used for is "is this mesh intersecting the ray between A and B".

Adbot
ADBOT LOVES YOU

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
Regarding my prefab crap, I can probably use the EditorSceneManager.activeSceneChanged event to do my bidding. I have to dabble in it to be sure, but it reads like the kind of thing I wanted.

Edit: Apparently not. This is for when one scene becomes another versus something changing in the current scene. You see some strange stuff online about all this stuff...

Edit Edit: EditorApplication.hierarchyWindowChanged seems to do the job. I can drop a prefab down and then take a peek to see if I care about it:
code:
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;

[InitializeOnLoad]
public class ItemEditorIntegration
{
    static bool Initialized = false;

    // Heard something about the constructor getting called twice so I'd like to make sure we only
    // register the event handler once.
    static ItemEditorIntegration()
    {
        if(!Initialized)
        {
            EditorApplication.hierarchyWindowChanged += OnHierarchyWindowChanged;
            Initialized = true;
        }
    }

    public static void OnHierarchyWindowChanged()
    {
        // TODO: Interrogate the selection to see if it's an item that needs to be unpacked.
        Debug.Log("Yay! Hierarchy changed!");
        foreach(var obj in Selection.objects)
        {
            if(obj is GameObject)
            {
                Debug.Log("Selected GameObject: " + obj.name);
            }
        }
    }
}
#endif

Rocko Bonaparte fucked around with this message at 15:12 on Dec 19, 2017

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
If you want to know what seems to work, this is what I figured out for OnHierachyWindowChanged()
code:
    public static void OnHierarchyWindowChanged()
    {
        if (Selection.activeGameObject != null && PrefabUtility.GetPrefabType(Selection.activeGameObject) == PrefabType.PrefabInstance)
        {
            var itemComponent = Selection.activeGameObject.GetComponent<ItemBehaviour>();
            if(itemComponent != null)
            {
                itemComponent.DropInWorld(null);

                // Let's just make sure it'll get a scene ID and object ID...
                Selection.activeGameObject.GetOrCreateComponent<HasSceneObjectId>();
            }
        }
    }
So now I can have my prefab sitting pretty in the resources folder with just the item's very particular script. It will call DropInWorld() on it, which is equivalent to what would happen if an entity dropped the item in the world. Since it was dropped by nothingness, I pass null. Also, GetOrCreateComponent is a shorthand extension method I wrote to either get an existing MonoBehaviour or create a new one and use that instead.

This lead to some materials shenanigans in DropInWorld(). I'm attaching a MeshRenderer, Meshfilter, BoxCollider, and my own sauce there, and I have to specify the texture. Unity gets really mad that I'm not assigning this to sharedMaterial in-editor. To be honest, I don't really understand the significance of sharedMaterial versus a regular material; the editor explains the ramifications of it but not why the editor is so fussy about using it and why I leak if I don't. If it'll jar somebody's memory, the error was "Instantiating material due to calling renderer.material during edit mode. This will leak materials into the scene. You most likely want to use renderer.sharedMaterial instead."

I did a very cargo-cult thing to get it to work because sharedMaterial was null walking into a new MeshRenderer:

code:
        // Life used to be so easy. I could just do this, but Unity gets mad about not using sharedMaterial when I call this in-editor:
        //meshRenderer.material.mainTexture = Resources.Load<Texture2D>("models/sledge");

        // The boneyard, takes 1 and 2
        //meshRenderer.sharedMaterial.mainTexture = Resources.Load<Texture2D>("models/sledge");
        //meshRenderer.sharedMaterials[0] = Resources.Load<Texture2D>("models/sledge");

        // The boneyard, take 3
        //Material[] sharedMaterialsCopy = meshRenderer.sharedMaterials;
        //sharedMaterialsCopy[0].mainTexture =
        //meshRenderer.sharedMaterials = sharedMaterialsCopy;

        // Finally, this works. But at what cost?
        Material meshMaterial = new Material(Shader.Find("Diffuse"));
        meshMaterial.mainTexture = Resources.Load<Texture2D>("models/sledge");
        meshRenderer.sharedMaterial = meshMaterial;
I had to create a Material and specify something to it, so I gave it the diffuse shader. I can finally slap the texture on it and assign it. First, what the hell is this shared material stuff and why is the editor so fussy about it over a regular material? Second, am I doing this in a good way? Can I expect an anvil to fall in my head at any moment from doing this?

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I'm now doing the normal thing of trying to manage collisions and physics in Unity again. In this case, I want to drop an item in the world and have gravity plop it where it belongs. I then want my player to be able to pick it up again. The latter would be served by a MonoBehaviour diverting OnCollisionEnter/OnTriggerEnter to a routine that checks if the target matches all the rules; all I really need is for those callbacks to run at all. The player is using a character controller with a capsule collider. The bulk of the control is managed by InControl. I gave the item a RigidBody just so I could give it gravity. It is not set to be a trigger; if it was, then it falls straight through the world. The world is done with ProBuilder Detail entities.

Right now, the object falls, hits the world, and stops. The collision callbacks don't run even if I'm driving my player all over the item like a tonka truck. What I am thinking of changing is creating a second game object just for the item giver script, assigning that a spherical collider that is a trigger. I would assign that to the falling item; I assume the collider would follow with it. I'd have to rewrite the logic a little bit and probably create a utility function to manage it. I can see it working, but is it an optimal way of solving the problem?

Edit: I guess I can just throw more colliders right on the same GameObject. Thanks for being my rubber ducky!

Rocko Bonaparte fucked around with this message at 22:05 on Dec 24, 2017

Tiler Kiwi
Feb 26, 2011
Not a question at all but I just feel like sharing a happy moment I've been having. I've been doing planning on paper without doing any actual coding and was starting to wonder if I was just mucking about, but I suddenly managed to have a real epiphany thanks to taking time to think things through even when it didn't feel like it was fitting together. I finally feel like I really "get" why inversion of control and events/delegates are such a good and powerful things, instead of just doing it because people told me it was smart.

Essentially, I've worked out a plan to have a lot of my game's logical stuff carried out via Interactions, which are just serialized objects. They take a list of Targets, which have conditions for acceptability, and have a list of Effects which do things to targets. Effects are just kind of wrappers for functions that turn the generic Targets into parameters to call the functions with. The "aha" moment came when I came to realize that, by instead of doing things like "Okay its an attack from an Actor to an Actor, so it does Actor.Item.Weapon.DamageValue amount of damage and, uh, poo poo, what about modifiers like armor and the weather and alignment of planets, I guess I need to know all that too, poo poo now I can't change anything, and gently caress what if I make a new item type gently caress gently caress", I could now just throw whatever generic Targets I want to Effects and now, suddenly, its the function's job to sort out all that nonsense, and the function can just hand the bag down to the Targets themselves and essentially tell them "Yo you're being attacked by This, which says its attacking with This damage, sort your own poo poo out". So suddenly these Interactions can operate like they're just working in a kind of dream logic where they don't actually have to care about anything else's implementation anymore. If something fails to work it can crash or do something else but its no longer the concern of the higher level stuff at that point, its instead something like "I actually dunno what to do when attacked by a, uh, brick wall???" and now instead of having to shuffle a bunch of ultra dependent poo poo around that breaks whenever the underlying stuff changes at all, its just modifying some function somewhere to accommodate things, or modifying the target conditions to disallow that interaction.

It suddenly feels like once I get this poo poo in place, and create a few interactions and hand them to the right stuff, and get the UI to know how to generate an appropriate interface for providing targeting information from the user, that I could throw together basically anything I want and not have to care if I decide to change everything out from under it. I'm actually feeling pretty excited to implement this and find out where my train of thought fucks up terribly and makes me miserable again.

e: doing more messing with it, this is probably a very good place to work in some Event system for dealing with Effects, or something like that. It seems like an ideal fit.

Tiler Kiwi fucked around with this message at 14:14 on Dec 29, 2017

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Persistent Hamprince posted:

Not a question at all but I just feel like sharing a happy moment I've been having. I've been doing planning on paper without doing any actual coding and was starting to wonder if I was just mucking about, but I suddenly managed to have a real epiphany thanks to taking time to think things through even when it didn't feel like it was fitting together. I finally feel like I really "get" why inversion of control and events/delegates are such a good and powerful things, instead of just doing it because people told me it was smart.

Essentially, I've worked out a plan to have a lot of my game's logical stuff carried out via Interactions, which are just serialized objects. They take a list of Targets, which have conditions for acceptability, and have a list of Effects which do things to targets. Effects are just kind of wrappers for functions that turn the generic Targets into parameters to call the functions with. The "aha" moment came when I came to realize that, by instead of doing things like "Okay its an attack from an Actor to an Actor, so it does Actor.Item.Weapon.DamageValue amount of damage and, uh, poo poo, what about modifiers like armor and the weather and alignment of planets, I guess I need to know all that too, poo poo now I can't change anything, and gently caress what if I make a new item type gently caress gently caress", I could now just throw whatever generic Targets I want to Effects and now, suddenly, its the function's job to sort out all that nonsense, and the function can just hand the bag down to the Targets themselves and essentially tell them "Yo you're being attacked by This, which says its attacking with This damage, sort your own poo poo out". So suddenly these Interactions can operate like they're just working in a kind of dream logic where they don't actually have to care about anything else's implementation anymore. If something fails to work it can crash or do something else but its no longer the concern of the higher level stuff at that point, its instead something like "I actually dunno what to do when attacked by a, uh, brick wall???" and now instead of having to shuffle a bunch of ultra dependent poo poo around that breaks whenever the underlying stuff changes at all, its just modifying some function somewhere to accommodate things, or modifying the target conditions to disallow that interaction.

It suddenly feels like once I get this poo poo in place, and create a few interactions and hand them to the right stuff, and get the UI to know how to generate an appropriate interface for providing targeting information from the user, that I could throw together basically anything I want and not have to care if I decide to change everything out from under it. I'm actually feeling pretty excited to implement this and find out where my train of thought fucks up terribly and makes me miserable again.

e: doing more messing with it, this is probably a very good place to work in some Event system for dealing with Effects, or something like that. It seems like an ideal fit.

You’re using Unity, yeah?

this talk isn’t bad event stuff around 28:00, but the rest is probably worth watching

Tiler Kiwi
Feb 26, 2011
thanks. i was actually not really familiar with scriptable objects until you mentioned them a while ago, so that was a bit of advice that turned out to be super helpful.

Doc Block
Apr 15, 2003
Fun Shoe
If I'm making a game for Windows and Mac, how sorry am I gonna be later on for manually maintaining the Visual Studio and Xcode projects? It feels like I should use CMake or something to generate them, but on the other hand I won't be distributing the source code, so no need for using CMake to make sure whoever is doing the build is using a compiler that supports all the C++11/14 features used, where they have SDL installed, etc.

I'm aware that I'll have to update both projects every time I added or removed a file, but most of the development is gonna be done on one platform and then just ported to the other, so that shouldn't happen too often. And it seems like using the CMake-generated project files to do the actual development work would be annoying. Maybe keep a separate project for development and use CMake to generate the build systems for building release binaries?

Ideas? Or should I ask this in the C++ megathread?

Doc Block fucked around with this message at 21:44 on Dec 29, 2017

Workaday Wizard
Oct 23, 2009

by Pragmatica
wasn’t there a hot new cpp build system? meson i think

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Shinku ABOOKEN posted:

wasn’t there a hot new cpp build system? meson i think
You could use Google's bazel build system. As a product of Google it's sure to be supported for years to come, just like Google Code, Google Reader, Google's XMPP servers, or an Android device from more than two years ago.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

roomforthetuna posted:

You could use Google's bazel build system. As a product of Google it's sure to be supported for years to come, just like Google Code, Google Reader, Google's XMPP servers, or an Android device from more than two years ago.

https://www.gwern.net/Google-shutdowns

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
I’m probably dumb but I’d use a build system if I had more than two platforms to support.

Chainclaw
Feb 14, 2009

Doc Block posted:

If I'm making a game for Windows and Mac, how sorry am I gonna be later on for manually maintaining the Visual Studio and Xcode projects? It feels like I should use CMake or something to generate them, but on the other hand I won't be distributing the source code, so no need for using CMake to make sure whoever is doing the build is using a compiler that supports all the C++11/14 features used, where they have SDL installed, etc.

I'm aware that I'll have to update both projects every time I added or removed a file, but most of the development is gonna be done on one platform and then just ported to the other, so that shouldn't happen too often. And it seems like using the CMake-generated project files to do the actual development work would be annoying. Maybe keep a separate project for development and use CMake to generate the build systems for building release binaries?

Ideas? Or should I ask this in the C++ megathread?

How easy is it to figure out when you make a mistake and forget to add a file to one solution and not the other? If it's difficult and leads to unexpected problems, then that's a point for automation. If it's obvious that something's wrong, and obvious how to fix it, then automation isn't as necessary.

How much time are you spending maintaining those solutions right now? How many files do you add day to day? If you're adding a ton, then the automation investment is worth it.

How often do you avoid making new C++ files and instead shove stuff into existing files, even when it doesn't make sense or kind of breaks your standard? If you're not creating new files as often as you should, then it might be because you've made it difficult to create new files and you're avoiding updating those solutions.

Autogenerated solutions and projects are great when done correctly. It is easy to gently caress up the automation, and it's also easy to go down a bad rabbit hole and spend way more time on an automated solution than you end up saving.

Absurd Alhazred
Mar 27, 2010

by Athanatos

roomforthetuna posted:

You could use Google's bazel build system. As a product of Google it's sure to be supported for years to come, just like Google Code, Google Reader, Google's XMPP servers, or an Android device from more than two years ago.

Or Tango.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
Keep in mind that if you're doing C++ builds on Windows that you expect to be portable to any non-MS platform and you're using templates at all, you need to constantly check that your code is still compiling on that other platform because MS's C++ compiler is extremely over-permissive about parsing identifiers in template code.

Doc Block
Apr 15, 2003
Fun Shoe

Chainclaw posted:

How easy is it to figure out when you make a mistake and forget to add a file to one solution and not the other? If it's difficult and leads to unexpected problems, then that's a point for automation. If it's obvious that something's wrong, and obvious how to fix it, then automation isn't as necessary.

How much time are you spending maintaining those solutions right now? How many files do you add day to day? If you're adding a ton, then the automation investment is worth it.

How often do you avoid making new C++ files and instead shove stuff into existing files, even when it doesn't make sense or kind of breaks your standard? If you're not creating new files as often as you should, then it might be because you've made it difficult to create new files and you're avoiding updating those solutions.

Autogenerated solutions and projects are great when done correctly. It is easy to gently caress up the automation, and it's also easy to go down a bad rabbit hole and spend way more time on an automated solution than you end up saving.

I haven't started the game yet, but I'm most likely gonna do all/most of the development on Mac and then port to Windows, since I'm a Mac crybaby and am a lot more familiar with macOS than Windows. So having to mess around with adding/removing/renaming files for both at the same time shouldn't be too big of an issue.

OneEightHundred posted:

Keep in mind that if you're doing C++ builds on Windows that you expect to be portable to any non-MS platform and you're using templates at all, you need to constantly check that your code is still compiling on that other platform because MS's C++ compiler is extremely over-permissive about parsing identifiers in template code.

Thanks, I'll definitely keep this in mind.

Kobata
Oct 11, 2012

OneEightHundred posted:

Keep in mind that if you're doing C++ builds on Windows that you expect to be portable to any non-MS platform and you're using templates at all, you need to constantly check that your code is still compiling on that other platform because MS's C++ compiler is extremely over-permissive about parsing identifiers in template code.

It'll also help to add /permissive- to the compiler flags, they've been working on 'fixing' that issue. It's not perfect, but at least it makes you somewhat less likely to accidentally break on other compilers.

Joda
Apr 24, 2010

When I'm off, I just like to really let go and have fun, y'know?

Fun Shoe
If anything, won't permissive make it less likely to compile on other systems? The only thing compilers have in common is the ISO standard, so being permissive in terms of breaking the rules of the standard, raises the chances of it breaking on another compiler, right?

Kobata
Oct 11, 2012

Joda posted:

If anything, won't permissive make it less likely to compile on other systems? The only thing compilers have in common is the ISO standard, so being permissive in terms of breaking the rules of the standard, raises the chances of it breaking on another compiler, right?

The 'default' is permissive, MS's compiler flags use '-' at the end to signify disabling something.

(The idea seems to be they'll make it disabled by default eventually, at which point it becomes just `/permissive' to re-enable it for older MS-specific stuff)

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
I came up with an unusually plausible new year's resolution - having done adventofcode last month, I realized I quite enjoyed doing a bite-sized programming challenge every day at 9pm, and kind of missed it when it was over, so now that there is no adventofcode my resolution is to make my own similar-sized challenges - come up with a bite-sized development task for my game each day before 9pm, and then implement it at/around 9pm.

Today I chose adding some sound effects to the tutorial room that's all that exists so far (having not done any sound in Godot before). Turns out recording, editing, learning how to get it into Godot and scripting functioning triggers for it into my text dialog can all be done in less than 45 minutes. Noice.

Linear Zoetrope
Nov 28, 2011

A hero must cook
Is Unity the only one of the bigger engines that has full tess shader support? I wanna mess around with some really experimental geometry generation (basically messing with the surface depending on the viewpoint of the camera and general things that Real Shapes Do Not Do, and no, a vertex shader isn't sufficient because I need the patch generation), but it looks like UE4 only has support for really basic displacement mapping and Godot none at all.

Linear Zoetrope fucked around with this message at 07:28 on Jan 2, 2018

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
Can anybody think of a cute way to rotate icons for a ring menu using the new Unity UI? I can set up the menu just fine with basic sine/cosine, and I can just offset that over time based on what I want to do. However, I have this nagging feeling I could do something with anchors. I don't want the icons themselves to rotate, but rather I want the position of the icons to rotate around a center. I figured I could do something by setting their anchors to the center, or parenting them to something that is centered, and then just do a rotation on that one thing. I suspect I then have to do something else to lock the raw images so they don't rotate along with the position.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Rocko Bonaparte posted:

Can anybody think of a cute way to rotate icons for a ring menu using the new Unity UI? I can set up the menu just fine with basic sine/cosine, and I can just offset that over time based on what I want to do. However, I have this nagging feeling I could do something with anchors. I don't want the icons themselves to rotate, but rather I want the position of the icons to rotate around a center. I figured I could do something by setting their anchors to the center, or parenting them to something that is centered, and then just do a rotation on that one thing. I suspect I then have to do something else to lock the raw images so they don't rotate along with the position.

Set rotation (not localRotation) to zero [in code]? If they’re not going to move around in game, you can just get things lined up and you’re fine.

e: you may want to do a look at at the camera instead if you’re in a 3d environment.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

leper khan posted:

Set rotation (not localRotation) to zero [in code]? If they’re not going to move around in game, you can just get things lined up and you’re fine.

e: you may want to do a look at at the camera instead if you’re in a 3d environment.

They'd be moving in-game. I'm assuming a Secret of Mana ring menu where 12 o'clock is the cursor and right/left rotates the elements clockwise/counter-clockwise.

Just to really hammer in what I'm doing, if it were a clock, then all the hours would be upright. If I turn the clock, the hours should all still be upright even if they have rotated around a common center. At the moment, each hour is a Unity new-style UI RawImage. I was figuring that each of these objects has a transform so I am thinking I could set something up to use that instead of doing a bunch of trig every frame as things progressively rotate.

Chainclaw
Feb 14, 2009

When I want to parent position and not rotation in Unity, I usually set it up like this: Create some child objects on the parent with no visuals. Offset them as I need. Create a separate object with visuals that is not in that hierarchy. Create a new C# component that has a public Transform. Attach that script to the visual object, and set the public transform to the child object I want this to follow. In one of the updates (LateUpdate or FixedUpdate, I forget the best one for timing) for that script, I call SetPosition on the local object, setting it to the position of the referenced transform.

The downside to this is your Unity hierarchy may be a hassle to manage. Also, if you have other important info in that hierarchy, like render order, it may be a pain in the rear end.

If you need it in the hierarchy, then another solution is I use is: Create an intermediate child between the center of the circle and the object that is rendering. Have this center child have the offset position. On the final child, the renderable, the math gets much simpler because your local position will be 0,0,0, so you can set your rotation to whatever.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Rocko Bonaparte posted:

They'd be moving in-game. I'm assuming a Secret of Mana ring menu where 12 o'clock is the cursor and right/left rotates the elements clockwise/counter-clockwise.

Just to really hammer in what I'm doing, if it were a clock, then all the hours would be upright. If I turn the clock, the hours should all still be upright even if they have rotated around a common center. At the moment, each hour is a Unity new-style UI RawImage. I was figuring that each of these objects has a transform so I am thinking I could set something up to use that instead of doing a bunch of trig every frame as things progressively rotate.

You don't need to do any trig. Just set the rotation to 0 on LateUpdate.

KillHour
Oct 28, 2007


You can also use rotatearound for the position and set the rotation manually after that.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

leper khan posted:

You don't need to do any trig. Just set the rotation to 0 on LateUpdate.

The trig is for positioning the RawImages. I calculate the angle between RawImages by dividing the number of them by 2pi. The x,y coordinates then are just r*sin(angle*i),r*cos(angle*i) around my center point. Currently I'm just recalculating that each frame based on which element is selected and some offset voodoo to try to animate it.

The question is if I can set up some shenanigans with a parent transform that serves as the pivot and have the whole mess of RawImages rotate around that from one command. I'd probably still at least use the trig code to set up the initial positions.

That being said, having a MonoBehaviour on each involved object going, "Oh! You want me to rotate? Vetoed!" does sound like a very novel way to prevent them locally rotating the each RawImage.

Chainclaw posted:

When I want to parent position and not rotation in Unity, I usually set it up like this: Create some child objects on the parent with no visuals. Offset them as I need. Create a separate object with visuals that is not in that hierarchy. Create a new C# component that has a public Transform. Attach that script to the visual object, and set the public transform to the child object I want this to follow. In one of the updates (LateUpdate or FixedUpdate, I forget the best one for timing) for that script, I call SetPosition on the local object, setting it to the position of the referenced transform
...

I kind of figured it might end up being something like that. You're basically declaring a waypoint for each visual item and tying them at the hip, if I read this all right.


KillHour posted:

You can also use rotatearound for the position and set the rotation manually after that.
Do you mean for each RawImage? I suppose it would be better than writing out the math I just did. I couldn't figure out which rotation method was valid for all this. I tried RotateAngle, which was deprecated, and it spun the RawImage around in-place. I think I still had to set an initial position.

BirdOfPlay
Feb 19, 2012

THUNDERDOME LOSER

Rocko Bonaparte posted:

The trig is for positioning the RawImages. I calculate the angle between RawImages by dividing the number of them by 2pi. The x,y coordinates then are just r*sin(angle*i),r*cos(angle*i) around my center point. Currently I'm just recalculating that each frame based on which element is selected and some offset voodoo to try to animate it.

The question is if I can set up some shenanigans with a parent transform that serves as the pivot and have the whole mess of RawImages rotate around that from one command. I'd probably still at least use the trig code to set up the initial positions.

That being said, having a MonoBehaviour on each involved object going, "Oh! You want me to rotate? Vetoed!" does sound like a very novel way to prevent them locally rotating the each RawImage.

Why are you dicking around with exact positioning on your own? Unity can handle rotation via Transform (in this case, RectTransform). It is one of the core transformation operations. No need to roll you own with a sine and cosine method per point. Also, there's simpler ways to get the points of a circle that don't require 2 * n trig function calls.

Yes, shenanigans with the parent is exactly what you should want to do! This gives you a stable "base" for your menu. I would create a (possibly empty) parent GameObject for your menu that you rotate. From there, you can populate your menu options around the outside of it with a simple locking Behavior that resets the RectTransform rotation to Quat.identity*.

Here's the finished product in action:


Inside my canvas I have a Menu. The two little dudes are children of Menu and positioned at 12 and 3 o'clock, and only the one at 3 has the locking behavior. All I'm doing is rotating Menu's z-axis via its RectTransform. Your menu control should be controlling Menu's rotation, which can be done with overriding the rotation with one generated via one of the static Quat methods.

*This is what leper means by zeroing it out.

BirdOfPlay fucked around with this message at 04:10 on Jan 5, 2018

Linear Zoetrope
Nov 28, 2011

A hero must cook
E: nm

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I mostly just figured it out, although I'm still a bit frazzled about the anchor positions and pivots in the Unity UI system. As for not having to do the initial sin/cos bit at all, I assume what I should be doing it taking each item, anchoring it a radius above my center, and then rotating it by it's index * Count/2pi around the Z axis from the center or something. Is that what you're alluding to?

Edit: What really got me was that I had to specifically set my ring center object's RectTransform anchor position to (0, 0). It would otherwise put it in a strange place. The HUD canvas had a centered anchor and pivot, and I would have assumed attaching a child object with a default RectTransform would put it smack in the middle but noooooo.

Rocko Bonaparte fucked around with this message at 07:44 on Jan 5, 2018

Tiler Kiwi
Feb 26, 2011

BirdOfPlay posted:

Also, there's simpler ways to get the points of a circle that don't require 2 * n trig function calls.

This statement led me to spend several hours playing around with circles and what little knowledge i have of finding arbitrary points in a circular orbit without trig functions and uh, as enlightening as that was I didn't figure out what you're alluding to. Everything I checked pretty much said "just do trig functions on the angle and center" so I'm stumped I guess.

Reveal to me your secrets.

I did learn that looking at any arbitrary point on an orbit you're on, presuming you know your own angle from the center, is just (angle1+angle2)/2 + 90 (with maybe some variation if a1+a1>=360 i guess idk im bad at math. from there i figured out you can get some other angles without trig functions, and maybe figure out the distance between you and said other point without trig functions (a big maybe actually), and presumably there's some other fuckery that i came to conclude was probably more complex than just doing some trig calls so aaaaa why didnt i pay attention in schoooool

KillHour
Oct 28, 2007


The point was that you shouldn't be DIRECTLY calling trig functions if you can avoid it. The native transform methods may use trig on the back end, but they're super optimized (I actually don't think they do, though. Unity uses quaternions for all that rotation nonsense).

BirdOfPlay
Feb 19, 2012

THUNDERDOME LOSER
^Well, that particular bit was that you didn't need to find the sine and cosine of every interior angle of a circle to get your values. In general though, it is better to just let Unity handle it, rather than rolling your own. Even in my little 2D shooter, I'm using a muzzle child object to represent were a shot is spawn and how it should be oriented. I don't need to figure out where the "out" direction and position is, because the Transform of the muzzle moves and rotates with the gun/character. I can even just roll a random Quaternion rotation from a range of rotations (via a lerp) and multiply that to the right of the muzzle's rotation to simulate spread.

Tiler Kiwi posted:

This statement led me to spend several hours playing around with circles and what little knowledge i have of finding arbitrary points in a circular orbit without trig functions and uh, as enlightening as that was I didn't figure out what you're alluding to. Everything I checked pretty much said "just do trig functions on the angle and center" so I'm stumped I guess.

Reveal to me your secrets.

I did learn that looking at any arbitrary point on an orbit you're on, presuming you know your own angle from the center, is just (angle1+angle2)/2 + 90 (with maybe some variation if a1+a1>=360 i guess idk im bad at math. from there i figured out you can get some other angles without trig functions, and maybe figure out the distance between you and said other point without trig functions (a big maybe actually), and presumably there's some other fuckery that i came to conclude was probably more complex than just doing some trig calls so aaaaa why didnt i pay attention in schoooool

The key is that it wasn't for arbitrary points on a circle, but equidistant points to form a circle.

Remember your Linear Algebra and rotations. Making a unit circle is just (1, 0) rotated around the center. Here's a little pseudo code for it. Where pointCount is just how many points you want on your circle.
code:
float sinTheta = sin(angle);
float cosTheta = cos(angle);
float x, y;

List<Vector2> theCircle = new List<Vector2>(pointCount);

// Prime the pump
theCircle.Add(new Vector2(1.0f, 0.0f ));
for (int i = 1; i < pointCount; i++)
{
	x = theCircle[i-1].x * cosTheta - theCirlce[i-1].y * sinTheta;
	y = theCircle[i-1].x * sinTheta + theCircle[i-1].y * cosTheta;
	theCircle.Add(new Vector2(x, y));
}
If you wanted a circle with a radius that wasn't 1, just multiply all the points by the desired radius, i.e. scale it to fit.

Also, it may be that making a hundred trig calls (for a 50-point circle) is no big deal, but

BirdOfPlay fucked around with this message at 21:11 on Jan 5, 2018

revolther
May 27, 2008

BirdOfPlay posted:

Here's the finished product in action:

I think they want everything to stay vertically oriented and readable, in your example all the little rocket bikes would stay facing left to right as they rotate. In Unreal you could just stick em to a thing, rotate the thing, and update their individual globalrotation or localrotation to zero each frame of the transition.

BirdOfPlay
Feb 19, 2012

THUNDERDOME LOSER

revolther posted:

I think they want everything to stay vertically oriented and readable, in your example all the little rocket bikes would stay facing left to right as they rotate. In Unreal you could just stick em to a thing, rotate the thing, and update their individual globalrotation or localrotation to zero each frame of the transition.

... That's exactly what's happening here. :geno:

Granted the one that starts at 12 isn't locked, but I also said that in the post.

Tiler Kiwi
Feb 26, 2011

BirdOfPlay posted:

List<Vector3> Circle ...

Oh, neat! I thought that such a thing was what you were getting at, but I wanted to make sure, just in case there was some super clever math trick I hadn't learned. I did decide, tho, that Circles are Cool, so it wasn't a total waste of time.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

BirdOfPlay posted:

Remember your Linear Algebra and rotations.
Nah there was no way I was going to be figuring that one out. I was absolutely behind in high school math when a lot of this was first introduced and I never really recovered on the algebra side. Calculus was interesting though because everybody basically had to start from scratch so I did great... except when things got a little involved in the arithmetic. I wish I could find a good algebra diagnostic to figure out what stuff I honestly never really learned.

Even my linear algebra stuff was just matrices out the rear end.

Edit: It was the damndest thing because I majored in computer engineer. For all my courses, I survived basically because I could model everything I needed in my equations but would botch solving for X. I got my lower grades in the courses where the professor valued starting wrong and calculating that correctly than starting right and calculating incorrectly. ...yeah.

Rocko Bonaparte fucked around with this message at 07:36 on Jan 7, 2018

Love Stole the Day
Nov 4, 2012
Please give me free quality professional advice so I can be a baby about it and insult you

Rocko Bonaparte posted:

Nah there was no way I was going to be figuring that one out. I was absolutely behind in high school math when a lot of this was first introduced and I never really recovered on the algebra side. Calculus was interesting though because everybody basically had to start from scratch so I did great... except when things got a little involved in the arithmetic. I wish I could find a good algebra diagnostic to figure out what stuff I honestly never really learned.

Even my linear algebra stuff was just matrices out the rear end.

Edit: It was the damndest thing because I majored in computer engineer. For all my courses, I survived basically because I could model everything I needed in my equations but would botch solving for X. I got my lower grades in the courses where the professor valued starting wrong and calculating that correctly than starting right and calculating incorrectly. ...yeah.

This is a really good video series that you can watch casually. It focuses only on the ideas and almost never bothers you with the numbers and letters: https://www.youtube.com/playlist?list=PLZHQObOWTQDPD3MizzM2xVFitgF8hE_ab

Adbot
ADBOT LOVES YOU

TerraGoetia
Feb 21, 2011

A cup of spiders.
Trying to compute line of sight is causing me headaches. I wrote something up based on what I remember from high school algebra, but I end up seeing through walls sometimes. I want line of sight to be useful for targeting ranged abilities, so I can't pass it off as a quirk.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply