So much of being a programmer
seems to be figuring out just how to get the syntax to work for you. When I still
worked in industry I remember that many of the Engineers had three or four
books on their desks at all times. I understand why more now. Often half of the
battle seems to be leafing through Unity’s website and looking at example code
and then saying, “Oh that it what this it for!”
Then
there are other times when really easy things are hard. I spent an entire
laptop battery trying to figure out how to get the angle of the trigger object
that my secondary weapon hit. I used my Google fu to try to find out how to do
this and because I was using ontrigger instead of oncollision this actually
seemed impossible to correctly set up given what I found. Fine! I will use
oncollision and make this secondary weapon use Unity’s physics. And that worked
I could get the angle BUT because I was scripting the motion of the object and
Unity’s physics was making the thrown object move in some super crazy ways. The
thrown object would sometimes fly off of the Z axis entirely. So the final
result was right but the trip to the result was just wrong.
This
was like probably two hours of trying and checking. Then someone broke a light
bulb over my head. Wait can’t I just col.Transform.rotation? OMG! I felt like
such an idiot for it taking me THAT long to figure out something so damn
simple. But then I saw it working and felt like such a champ for making it
work. The jury is still out on what is what.
Last
week I set up some crappy looking secondary weapons. Well two of them where
crappy the first one is still fine. I was reminded of something my animation
Professor in college said. “When the animation moves, you will feel amazed.
Don’t ever lose that. But the next step is then asking, how do I fix it?” When
I showed my wife who is a Physics teacher what I had set up and told her that
this weapon was supposed to be a parabola. She showed me how to make parabolic
motion work using an equation. We had one small hiccup with me not knowing the
Time.Deltatime is not the entire time an object’s existence and hence not equal
to elapsed time. After I had created an elapsed time variable it was super
parabolic!
Sending
a message through objects in Unity is kind of crazy. Or I should say that when
you have a target that can be hit by five different things but don’t know which
object hit the target, it seems kind of impossible. Or I could just use the
built in function SendMessage in Unity then passing values between objects
that don’t know about each other is actually completely possible. It really
boils down to, 'do I know what the information I need is called?' My Google fu for
this was ‘dealing damage in unity’. Found lots of things that were less than
helpful. Eventually found a really helpful tutorial. The tutorial wasn’t even
in C# but I was able to convert the Java to C#. That is how far I have come! I
really still can’t claim to be a master programmer but I seem to be figuring it
out. The end result was this though. I now have 4 secondary weapons that all
can deal damage to any object that is tagged as a Target. Pretty freaking neat!
Trying to find a way to pass
messages between objects took even longer than trying to figure out of to get
an angle of a slope that a was hit. I think it took me 3 hours to figure out
how to get that angle. It took me 6 to find a good way to talk to objects that
don’t know about each other. But again allow me to once again say this is
insanely fast! Unity is still stupid amazing!
No comments:
Post a Comment