Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 774 775 [776] 777 778 ... 795

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 820681 times)

Parsely

  • Bay Watcher
    • View Profile
    • My games!
Re: if self.isCoder(): post() #Programming Thread
« Reply #11625 on: March 12, 2020, 04:10:28 am »

Scaling these models down has been a huge pain in the ass. The models are all made of lots of little pieces and I can't check the dimensions unless the entire thing is joined. But sometimes there are a lot of floating vertices that make this impossible and they're a huge pain to hunt down and delete. What I've been doing is just joining the parts I want, copying that, selecting everything and deleting it, then pasting the model again. I hope I don't regret joining all the parts together.

I've gotten all these new models from the sketchup 3D warehouse; I can't understand why, but a lot of times the models I import don't resemble the one in the preview on the website. If all the pieces are there, the main fuselage is intact but there's almost always some extra bits that are just sitting there floating off to the side. On about 5 of the other models, there are no visible parts at all, or just a single floating vertex, or just a few bits of fuselage but nothing resembling a complete aircraft. I wish I knew if this was my error somehow, or if the artists just uploaded bad files...
Logged

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11626 on: March 13, 2020, 04:46:23 am »

What program are you using to edit them? If it's Blender I might be able to give you more specific tips, just point me a link to a problem model.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11627 on: March 13, 2020, 06:18:32 am »

Hmm... I've been making progress in the challenges I've set for myself. I'm playing with the standard C++ library, mostly. I've got a question, though, and maybe one of you can help out.

Generating a seed requires a number (srand(int)). I want to generate a seed based on a string. Not just taking the numbers out of a string and making that the seed, instead I want to be able to type 'delphonso' and get a numerical seed generated from that. Several games have this feature (rimworld and banished come to mind.) Anyone have a good suggestion of where I should start looking for this? Googling instead only gave me info on how to pull existing numbers out of seeds... Or just tell me to use time, but I'm interested to do it this way instead.

You could use a hash function as Putnam said.

My first instinct would be to just convert each character into a number 1-26 (or 0-25) and use that to seed the RNG.

When I made my planet generator and wanted seeds to be words, all I did was pad the string to a multiple of 4 characters long, then convert the raw pointer into an int* (force-cast), then went along the number of ints and added them together to get a single 32-bit int.

mko

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11628 on: March 13, 2020, 07:34:44 am »

I am playing with a procedural town/village/city simulator in Unity and I just spend plenty of time on debugging and reading documentation about colliders.

Root cause of a bug in field placement was

Code: [Select]
        crop.transform.position = size;

instead of

Code: [Select]
        crop.transform.position = center;

Hopefully I hit peak stupid for today.


EDIT: apparently my code is still broken, lets get back to docs and debug.

Code: [Select]
    public bool PlaceField(string identifier, float x, float z, float fieldSizeX, float fieldSizeZ) {
        float cropHeight = 0.3f;
        Vector3 center = new Vector3(x, cropHeight/2, z);
        Vector3 size = new Vector3 (fieldSizeX, cropHeight, fieldSizeZ);
        Vector3 halfSize = new Vector3 (size.x/2, size.y/2, size.z/2);

        if(Physics.CheckBox(center, halfSize)) {
            return false;
        }

        GameObject field = new GameObject();
        field.name = "field" + " " + identifier;

        GameObject crop = GameObject.CreatePrimitive(PrimitiveType.Cube);
        crop.GetComponent<Renderer>().material.color = new Color(0.9f, 0.9f, 0);
        crop.transform.parent = field.transform;
        crop.transform.position = center;
        crop.transform.localScale = size;
        crop.name = "crop" + " " + identifier;
        return true;
    }
« Last Edit: March 13, 2020, 07:37:35 am by mko »
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11629 on: March 13, 2020, 07:52:56 am »

I am playing with a procedural town/village/city simulator in Unity and I just spend plenty of time on debugging and reading documentation about colliders.

Root cause of a bug in field placement was

Code: [Select]
        crop.transform.position = size;

instead of

Code: [Select]
        crop.transform.position = center;

You know, a good trick in OO languages is to make a lightweight class which has semantics.

Spoiler (click to show/hide)

BTW for the way you're creating that object, there's meant to be one field object per crop, right? Just checking.

if the crop object is just the mesh/graphics, and they each get their own container called "field" then it's generally better to set the position on the parent object, and have the child objects all be relative to that. So you always leave "crop" at (0,0,0) and set the center on "field". Also, it's simpler to make sure you set the scaling on the root object to (1,1,1). This is because the root object scaling is then applied to all children objects. Which could get messy if they also need to be scaled relative to the root. So, set the "world" position on your root object but leave it without scaling, then put scaling on the children objects, but leave them in local coordinates (i.e. at 0,0,0). It's easier to manage this way.
« Last Edit: March 13, 2020, 08:26:09 am by Reelya »
Logged

Parsely

  • Bay Watcher
    • View Profile
    • My games!
Re: if self.isCoder(): post() #Programming Thread
« Reply #11630 on: March 13, 2020, 02:17:22 pm »

What program are you using to edit them? If it's Blender I might be able to give you more specific tips, just point me a link to a problem model.
I'm using Blender. I would love some help, thanks in advance! You can get me on discord too if you like: Parsely#7834

This is the problem model:
- https://3dwarehouse.sketchup.com/model/8957dff59d063d864f95630cc18536e0/Template-Piper-PA-34-Seneca
« Last Edit: March 13, 2020, 02:18:59 pm by Parsely »
Logged

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #11631 on: March 13, 2020, 02:26:09 pm »

@Reelya: May find it interesting if you don't know that some languages have a native feature for that too, F# calls them Units of Measure.

When you get the first-class language support, they can easily integrate things like meters-per-second in which you define two units of measure and the compiler can preserve them across conversions (5<meter>/2<second> = 2.5<meter/second>). Unfortunately this feature hasn't made it's way to C# yet but keep watching the skies language spec.
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11632 on: March 13, 2020, 05:20:33 pm »

I got something similar like that working in C++ using templates, at least for kg/m/s system units - using numerical templates representing the powers of each base unit.

you have to define the operators, and it will spit a compiler error if the bases don't match when doing an addition for example, so an m/s variable can only be added to an m/s variable, for example, but anything could be multiplied by anything else and it would output a new template type with the new powers of each unit.

Would be nice to rework that and see if it can have absolutely general units defined in the code.
« Last Edit: March 13, 2020, 05:25:44 pm by Reelya »
Logged

bloop_bleep

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11633 on: March 13, 2020, 08:50:40 pm »

Believe it or not, I was considering implementing something very similar to that myself at some point, Reelya.

Got me thinking after reading about that BS with the Mars Orbiter.
Logged
Quote from: KittyTac
The closest thing Bay12 has to a flamewar is an argument over philosophy that slowly transitioned to an argument about quantum mechanics.
Quote from: thefriendlyhacker
The trick is to only make predictions semi-seriously.  That way, I don't have a 98% failure rate. I have a 98% sarcasm rate.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11634 on: March 13, 2020, 09:10:04 pm »

Let me see if I can dig up the code.

Spoiler (click to show/hide)

If anyone wants to play with what I got working, that should be it. But I haven't run that code in a while, YMMV. Note that when storing the result of a computation, you can use auto as the return type, if you just want to store it, or you can typedef specific dimensions and give them a name, these are the ones already defined as an example:

typedef Dimensions<1, 0, 0> Kilogram;
typedef Dimensions<0, 1, 0> Metre;
typedef Dimensions<0, 0, 1> Second;

but you could make ones like these :

typedef Dimensions<0, 1, -1> Velocity;
typedef Dimensions<0, 1, -2> Acceleration;

To use these you make a "quantity<Velocity>" variable for example, but alternatively you could typedef the container type itself : typedef quantity<Dimensions<0, 1, -1>> Velocity;

So, what the goal would be is that all physics units that can be defined in the kms system can be typedef'd in this system, then hopefully, only physically meaningful computations would be allowed.

So, many SI units could be defined computationally with the code given:
https://en.wikipedia.org/wiki/SI_derived_unit

Hmm, I just realized if I add A, Amperes as a fourth dimension then I can add in a ton of the other SI units.
« Last Edit: March 13, 2020, 09:27:30 pm by Reelya »
Logged

mko

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11635 on: March 15, 2020, 03:50:32 pm »

Any idea what I am doing wrong here with https://docs.unity3d.com/ScriptReference/Physics.CheckBox.html ?

For some reason collisions are not detected where I would expect them to be.

Code: [Select]
        GameObject field = GameObject.CreatePrimitive(PrimitiveType.Cube);
        field.transform.position = new Vector3(10, 0, 5);
        field.transform.localScale = new Vector3(10, 1, 25);
        Assert.IsTrue(Physics.CheckBox(new Vector3(10, 0, 0), new Vector3(2.5f, 1, 2.5f)), "collision must be detected");

(10, 0, 0) is both within box centered at (10, 0, 0) and within box centered at (10, 0, 5) that has size (10, 1, 25).

repeated check:

(10, 0, 0) is within any nonzero box centered at (10, 0, 0)
(10, 0, 0) from (10, 0, 5) has distances (0, 0, 5), created cubes are (1, 1, 1), after scaling by (10, 1, 25) it will become box with sizes (10, 1, 25).

https://docs.unity3d.com/ScriptReference/Physics.CheckBox.html return true on detecting colliders

I am obviously missing something here, not sure what.

if the crop object is just the mesh/graphics, and they each get their own container called "field" then it's generally better to set the position on the parent object, and have the child objects all be relative to that. So you always leave "crop" at (0,0,0) and set the center on "field".
How I should do this in Unity? Because I initially tried setting real position at parent and Vector3(0, 0, 0) at child elements, but this placed all my trees at (0, 0, 0).

Setting in code position of parent objects at (10, 10, 10) and transform.position=Vector3(0, 0, 0) at child resulted in child getting (-10, -10, -10) offset.

Setting relative position within Unity Editor worked as expected and were actually relative, but ones set from code in transform.position are absolute ones.

For example, the multiplication operator for two lengths returns an "Area" object, so you can't accidentally multiply a length by another length and get a length. you need to multiply a length by a float for that.
It may be a good idea, and I will likely use something like that but in this case it would not really help, I would just do crop.transform.position = Sizeobject.size;



« Last Edit: March 15, 2020, 03:52:39 pm by mko »
Logged

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11636 on: March 15, 2020, 04:32:20 pm »

What program are you using to edit them? If it's Blender I might be able to give you more specific tips, just point me a link to a problem model.
I'm using Blender. I would love some help, thanks in advance! You can get me on discord too if you like: Parsely#7834

This is the problem model:
- https://3dwarehouse.sketchup.com/model/8957dff59d063d864f95630cc18536e0/Template-Piper-PA-34-Seneca

Unfortunately, I wasn't able to get very far with that model. I download the model as Collada (.dae) but when I import into Blender 2.78, it's just a few polygons out in space and a bunch of empties.

My only thought is that something is wrong with Sketchup's Collada export function, or there's some data the model maker used that can't be converted, like a bezier surface or something. I tried to open the model in Sketchup to see what the problem is, but the registration form is locked up and won't let me progress in either Firefox or Chrome. Sorry I couldn't help more :-\

Although if you do end up with the overlapping vertices problem on an otherwise-fine model, that's an easy fix. Just enter edit mode (tab,) then hit space and type "remove doubles." Any vertices within a certain distance of each other will be welded together. If the model is split up into multiple models, you can select all the pieces by pressing 'A' and then 'CTRL+J' to join the pieces into one model, where you can then join the vertices.
« Last Edit: March 15, 2020, 04:57:56 pm by itisnotlogical »
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11637 on: March 15, 2020, 06:06:56 pm »

How I should do this in Unity? Because I initially tried setting real position at parent and Vector3(0, 0, 0) at child elements, but this placed all my trees at (0, 0, 0).

Setting in code position of parent objects at (10, 10, 10) and transform.position=Vector3(0, 0, 0) at child resulted in child getting (-10, -10, -10) offset.

https://docs.unity3d.com/ScriptReference/Transform-localPosition.html

Use transform.localPosition to set position for elements in a way that respects the object hierarchy. Setting transform.position = Vector3(0, 0, 0) set the position in absolute terms, which was (-10, -10, -10) in local terms.

mko

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11638 on: March 15, 2020, 06:21:19 pm »

How I should do this in Unity? Because I initially tried setting real position at parent and Vector3(0, 0, 0) at child elements, but this placed all my trees at (0, 0, 0).

Setting in code position of parent objects at (10, 10, 10) and transform.position=Vector3(0, 0, 0) at child resulted in child getting (-10, -10, -10) offset.

https://docs.unity3d.com/ScriptReference/Transform-localPosition.html

Use transform.localPosition to set position for elements in a way that respects the object hierarchy. Setting transform.position = Vector3(0, 0, 0) set the position in absolute terms, which was (-10, -10, -10) in local terms.
Thank you! That was a missing part of the puzzle *goes to refactor code, ignores broken collision checks as I run out of ideas wtf is happening*
Logged

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11639 on: March 17, 2020, 03:30:35 am »

I feel like I have the beginnings of an okay-ish framework in Monogame. I can translate from screen coordinates to world coordinates, I have an actor system with a few Unity-like methods, I can pan and zoom the scene, and I have an input system that allows for key rebinding and distinguishing between multiple button states (pressed, released, held and up)

Next steps:
  • Audio. I have yet to even try playing sound with MonoGame. In this, I want a totally different idea from Unity; instead of audio being completely controlled by the GameObject/Actor playing it, there are predefined audio channels, and the actor requests said channel. Unity has this capability but IMO it's way more complicated than it needs to be.
  • Some sort of level/scene/room/whatever management. I hacked something together where it would use Activator to spawn actor classes from a text file, but I really don't like it--the class names must be fully qualified, and that's the least of my complaints about this setup.
  • Related to the above, some kind of level editor. I imagine this would be easier if I actually had some kind of game I was working on. Hand-writing a text file full of coordinates and class names isn't my favorite idea.
  • Enforcing the window's aspect ratio. I've followed a few examples but it didn't work and I haven't taken another crack at it yet.
« Last Edit: March 17, 2020, 03:32:23 am by itisnotlogical »
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.
Pages: 1 ... 774 775 [776] 777 778 ... 795