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
Joda
Apr 24, 2010

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

Fun Shoe
It should be noted that Slick2D, LibGDX and similar libraries does a lot of the draw code for you (whereas with Swing you need to make some amount of architecture for drawing and input handling yourself.) It depends on whether you just want to make a game and have the library do as much of the background stuff for you or you want some experience in making the background stuff yourself.

Slick2D, for instance, literally just takes a sprite, a size and a position and draws it for you. Obviously, you still have to make the game logic architecture yourself though.

Adbot
ADBOT LOVES YOU

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Joda posted:

It depends on whether you just want to make a game and have the library do as much of the background stuff for you or you want some experience in making the background stuff yourself.

This is such a huge question that should be asked internally more by everyone. I went from XNA to Futile2D and the change was pretty dramatic as far as what I needed to develop myself in the background. I've done more in one month in Futile than what I've done in several months in XNA.

By the way Tann, if you are getting somewhat comfortable with Java, know that C# is pretty much Microsoft's Java. The syntax is almost 100% identical. This really opens up your options as far as libraries go. I'll go ahead and toss out a recommendation for Futile since it's dead simple and lets you focus on writing a game. It's also built as a plugin for Unity so you get a lot of neat Unity stuff without having to actually touch Unity since Futile is entirely code driven. I only open Unity to hit the play button.

http://struct.ca/futile/ Watch the short video and then the 1 hour detailed video if you want to see a small project built from scratch.
http://www.reddit.com/r/futile Here's your "documentation". There's no docs for Futile but it's pretty intuitive what everything does and the 1 hour video explains enough to get just about anything going. MattRix is pretty good about answering questions there as well which is nice.

Tann
Apr 1, 2009

poemdexter posted:

By the way Tann, if you are getting somewhat comfortable with Java, know that C# is pretty much Microsoft's Java.

The reason I'm using Java is that I have a good friend who gives me invaluable advice when I get stuck with anything and he uses a mac. I hope that it won't end up keeping me back in the long run.
Thanks for the advice though, I'll definitely consider my options once I've finished my first big project but for now I'll try changing to Slick2D.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Tann posted:

The reason I'm using Java is that I have a good friend who gives me invaluable advice when I get stuck with anything and he uses a mac. I hope that it won't end up keeping me back in the long run.
Thanks for the advice though, I'll definitely consider my options once I've finished my first big project but for now I'll try changing to Slick2D.

I use a mac as well for Futile. Java is cross platform anyway, so development environment won't matter. Good luck with your project!

Joda
Apr 24, 2010

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

Fun Shoe
Last time I worked with Slick2D (about a month and a half ago) it didn't have natives for Mac OSX that worked with Java 7, so you might want to keep that in mind.

I hear LibGDX is very similar and about as easy to use, so that might be a better choice if you want something that does have JavaDocs.

E: Personally I prefer libraries with JavaDocs so I have an easy repository of descriptions for classes, interfaces and methods.

Joda fucked around with this message at 17:58 on Mar 11, 2013

bomblol
Jul 17, 2009

my first crapatar

poemdexter posted:

This is such a huge question that should be asked internally more by everyone. I went from XNA to Futile2D and the change was pretty dramatic as far as what I needed to develop myself in the background. I've done more in one month in Futile than what I've done in several months in XNA.

On the same note- the other page I was posting about getting collision detection working with SFML. I've done that and kind of learned a bit more about how some of the nitty gritty aspects of a 2D game engine work, which is nice... but I don't think I'm looking to do that on a regular basis, and would rather use a library/engine that can handle collision detection and other specifically game-oriented tasks, with C++ bindings. Or would this best be accomplished by using a physics package like Box2D?
I sure wish Polycode would finally be (re?)released.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

bomblol posted:

On the same note- the other page I was posting about getting collision detection working with SFML. I've done that and kind of learned a bit more about how some of the nitty gritty aspects of a 2D game engine work, which is nice... but I don't think I'm looking to do that on a regular basis, and would rather use a library/engine that can handle collision detection and other specifically game-oriented tasks, with C++ bindings. Or would this best be accomplished by using a physics package like Box2D?
I sure wish Polycode would finally be (re?)released.

What kind of collision detections are you handling that aren't covered by some Rectangle method called intersect that returns true/false in whatever language you are in?

Box2D will handle a lot of what you want by attaching collision objects to your entities. It can be a bit bloated if you're trying to stay simple, but I say give that a shot.

xgalaxy
Jan 27, 2004
i write code

bomblol posted:

On the same note- the other page I was posting about getting collision detection working with SFML. I've done that and kind of learned a bit more about how some of the nitty gritty aspects of a 2D game engine work, which is nice... but I don't think I'm looking to do that on a regular basis, and would rather use a library/engine that can handle collision detection and other specifically game-oriented tasks, with C++ bindings. Or would this best be accomplished by using a physics package like Box2D?
I sure wish Polycode would finally be (re?)released.

You can get the new polycode now off github.
It's in active dev though, so sometimes the build doesn't compile.
https://github.com/ivansafrin/Polycode

Lord Windy
Mar 26, 2010

Joda posted:

Last time I worked with Slick2D (about a month and a half ago) it didn't have natives for Mac OSX that worked with Java 7, so you might want to keep that in mind.

I hear LibGDX is very similar and about as easy to use, so that might be a better choice if you want something that does have JavaDocs.

E: Personally I prefer libraries with JavaDocs so I have an easy repository of descriptions for classes, interfaces and methods.

It isn't Slick2D that is broken, it is lwjgl (Slick2d dependancy) that has something that isn't working. This thread on their forum gives the current solution that I am using to fix the issue. They just had to rewrite their Mac section to update it to Java 7 after Apple changed something. Their next release will have the actual fix so you don't need to download Mac specific fixes.

It also does have a really amazing Javadoc, as does lwjgl if you wanted to use parts of that.

dick traceroute
Feb 24, 2010

Open the pod bay doors, Hal.
Grimey Drawer
Ok, I have an idea for an app. It's not really a game but it's dumb as gently caress (one might say pointless), so I guess it belongs here.

I want to release it for ios and android, and would like to write the code once and have to fiddle as little as possible.

Google shows a whole bunch of frameworks to do such a thing, but does anyone have any personal recommendations?

Performance isn't really an issue, as it's super simple. Back end needs a one (possibly two) table database. Front end is basically plug a number in and choose something from a menu. I might also release a web version and a Twitter robot using the same database.

Any suggestions?

Edit : I have not a Macintosh brand computer. Guess I kind of need one?

dick traceroute fucked around with this message at 19:03 on Mar 13, 2013

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!

Thumbquat posted:

Performance isn't really an issue, as it's super simple. Back end needs a one (possibly two) table database. Front end is basically plug a number in and choose something from a menu. I might also release a web version and a Twitter robot using the same database.
Back end, a PHP-mysql web server, because basically everything can communicate with that pretty easily. It's kind of lovely but it's easy to set up and it sounds like you're not likely to be running into performance issues enough to make it worth doing anything more intensive.

Front end, HTML5, because that will work with every device that has a browser. It sounds like you don't even need a canvas, so maybe even lovely old HTML!

I don't have a suggestion for making a cross-platform actual app, but if you're considering a web version then you might as well start with it because it'll be the easiest.

dick traceroute
Feb 24, 2010

Open the pod bay doors, Hal.
Grimey Drawer
I guess, yeah. Might as well make it in JavaScript and see if that's a nice base to work from. It's light enough I could even start over if I need to.

The King of Swag
Nov 10, 2005

To escape the closure,
is to become the God of Swag.
I originally posted this over at the Ogre3D forums earlier today, but their Help forum moves slower than this thread and I know there's a few Ogre users here that might be able to help. You would think this would be a very simple problem, but I can't find the answer anywhere on my own.

The King of Swag posted:

Hopefully this question will be easy to answer, but I've been going through the Cg Tutorial (and compiling it as HLSL because FX Composer doesn't support Cg) and I'm currently most of the way through the Lighting chapter (5). Up to this point, I've written and successfully gotten to work with Ogre, the per-pixel lighting example. The tutorial then suggests as good practice, that the lighting functionality be offloaded into its own function, and most of the lighting parameters be offloaded into structs, to make it easier to pass them along and group them, and make the eventual expansion of the shader easier.

Again, I've done that and the shader compiles without errors, but Ogre complains with this error:

code:
OGRE EXCEPTION(2:InvalidParametersException): Parameter called light0.color does not exist.  ...
... in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1451)
18:18:08: Compiler error: invalid parameters in TestMaterial.material(54): setting of constant failed
This error repeats for every parameter that has been moved into a struct; as you can see, I've attempted to access the struct members by using dot notation on the name of the struct in the argument list, and the struct member name. Although it doesn't seem to work, it was the way sinbad said to access the members in an old post I found (early 2008).

For good measure, here's the shader programs and material script I'm using. As you might notice, I've also added singular texture support to the Cg example. Although unrelated to my current problem, I had a monstrous time trying to get texturing to work, because the first two texture registers were being used for position and normal data needed for the lighting, and I couldn't figure out any way to make Ogre load a texture_unit into a specific register from the material file. I ended up using a shader example here on the site, which involves loading the texture uv data into the first texcoord register (being as there's only one texture), and then simply reusing that same texcoord for the position data, after saving the uv data.

/* I originally included the shaders and the material script here, but SA doesn't render code blocks inside of fixed width/height boxes like the Ogre3D forum does, and they take up a lot of screen-space, so in interest of not pissing everyone off with a huge wall of text, I'll just link to the original post on the Ogre3D forums if you'd like to see the code. */

How to set shader parameters that are part of structs?

ArcticZombie
Sep 15, 2010
I'm making a horizontal scrolling shmup and I've come unstuck with the enemy movement. I want some interesting movement patterns such as flying in loops, waves and along curves. I think I can use a parametric equation describing the pattern I want the ship to move in and moving it along by changing the ships t value. Currently I can get a ship to move in a circle with the following equation:

x = 75 + 200 * cos(t)
y = 46 + 200 * sin(t)


Every time it updates, t is increased by dt where dt is how often the game updates (1/120 of a second in this case). I want how fast the ship moves around the circle to be influenced by the ship's speed attribute. I know I'm going to have to change how much t is changed by and it is going to involve Pythagorean theorem but I can't work out how to put it all together.

Any help?

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
um, multiply the ship's speed by dt when you change t?

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
I'd strongly recommend making enemy patterns spline based, you can do practically approach very easily with that (including acceleration/deceleration), and deriving facing direction and speed (for presentation purposes) from a spline path are both completely trivial.

ArcticZombie
Sep 15, 2010

Internet Janitor posted:

um, multiply the ship's speed by dt when you change t?

I tried this and it didn't seem to work as I want it and I'm not sure how to fix it. If the player ship and the enemy ship have the same speed value, the enemy ship moves WAY faster than the player can.

OneEightHundred posted:

I'd strongly recommend making enemy patterns spline based, you can do practically approach very easily with that (including acceleration/deceleration), and deriving facing direction and speed (for presentation purposes) from a spline path are both completely trivial.

I'll look into this, it seems like it would make things easier.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

ArcticZombie posted:

I'm making a horizontal scrolling shmup and I've come unstuck with the enemy movement. I want some interesting movement patterns such as flying in loops, waves and along curves. I think I can use a parametric equation describing the pattern I want the ship to move in and moving it along by changing the ships t value. Currently I can get a ship to move in a circle with the following equation:

x = 75 + 200 * cos(t)
y = 46 + 200 * sin(t)


Every time it updates, t is increased by dt where dt is how often the game updates (1/120 of a second in this case). I want how fast the ship moves around the circle to be influenced by the ship's speed attribute. I know I'm going to have to change how much t is changed by and it is going to involve Pythagorean theorem but I can't work out how to put it all together.

Any help?

If you have motion of the form

x = R * cos(w*t)
y = R * sin(w*t)


Then the velocity is w*R. w is called the angular velocity. (I'm assuming everything is in radians here)

Edit: To explain a little more, if you have

x = cos(t)
y = sin(t)

Then every unit of time you move 1 radian around the circle. And since the circle in this case is of radius 1, 1 radian corresponds to 1 unit of distance (that's the definition of a radian), so you have a velocity of 1 in this case. If you increase the radius then the distance increases in proportion. And if you increase the angular velocity the radians per unit time also increases in proportion. So the velocity of the equation above is w * R.

HappyHippo fucked around with this message at 00:49 on Mar 15, 2013

Wolfgang Pauli
Mar 26, 2008

One Three Seven
Can you guys recommend any Unity tutorials and such that are actually good and helpful? Preferably something that will let me pick up C# along the way. I've been doing this and I don't think the official Unity video tutorials actually exist anymore.

FuzzySlippers
Feb 6, 2009

They are in the middle of updating the Unity learning assets so a lot of the links are missing. I think all of the Unity learning resources are in JS/Unity script anyway.

I never found any decent c# comprehensive Unity tutorials so I just followed along in a JS Unity book and converted the code over to c# along the way. I felt that was a decent one of getting my feet wet in c#. I can't actually recall which book it was I used but there are only a couple and I think most are well regarded.

JG_Plissken
Oct 22, 2005

I went to a four year college and all I got was this stupid look on my face!
I'm wanting to learn how to do some programming with SDL on my Mountain Lion Mac. I've made some games in the past with XNA and some HTML5 Canvas stuff. Should I be using SDL 1.2 or 2.0? I tried to download 2.0, but getting the framework assembled was kind of a disaster and I couldn't get it working. Supposedly SDL 2.0 was near ready mid last year, but the SDL site still says it is under development. I've seen some other cool SDL games, but is SDL worth getting into?

The Gripper
Sep 14, 2004
i am winner

JG_Plissken posted:

I'm wanting to learn how to do some programming with SDL on my Mountain Lion Mac. I've made some games in the past with XNA and some HTML5 Canvas stuff. Should I be using SDL 1.2 or 2.0? I tried to download 2.0, but getting the framework assembled was kind of a disaster and I couldn't get it working. Supposedly SDL 2.0 was near ready mid last year, but the SDL site still says it is under development. I've seen some other cool SDL games, but is SDL worth getting into?
I've never personally used it for anything other than messing around, but SFML seems to be what a lot of people are recommending in place of SDL lately. The downside is that SDL had more platform support (other than just Windows, OSX, Linux) but honestly I haven't compared them lately to say whether that's still the case or not. SDL is definitely less maintained than it ever has been before, though the actual choice islikely going to boil down to "use whatever works, buddy".

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
SDL is fairly well-maintained, and Valve uses it as their portability library for their games. I don't know the status of SDL 2.0, though, but SDL 1.2.15 was released a little over a year ago. It's still fine to use.

The thing is that SDL is not really a graphics library or a game engine. It's more of a portability library for various display systems, input systems, and audio systems, plus some utilities that are helpful for making games. It won't give you a convenient wrapper layer over OpenGL or Direct3D. If you want to make simple 2D games, you're welcome to use Direct2D, Quartz 2D or Skia/Cairo on top of it. If you want to make simple 3D games, the best thing I can say is to use OpenGL instead of Direct3D, but OpenGL isn't the friendliest API in the world.

libcxx
Mar 15, 2013
thread_local post<shit> shit_post("lol if u");

Suspicious Dish posted:

SDL is fairly well-maintained, and Valve uses it as their portability library for their games. I don't know the status of SDL 2.0, though, but SDL 1.2.15 was released a little over a year ago. It's still fine to use.

The thing is that SDL is not really a graphics library or a game engine. It's more of a portability library for various display systems, input systems, and audio systems, plus some utilities that are helpful for making games. It won't give you a convenient wrapper layer over OpenGL or Direct3D. If you want to make simple 2D games, you're welcome to use Direct2D, Quartz 2D or Skia/Cairo on top of it. If you want to make simple 3D games, the best thing I can say is to use OpenGL instead of Direct3D, but OpenGL isn't the friendliest API in the world.

Are there any good tutorials for Skia anywhere? All I've ever found is the official docs, which can be a bit bare.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
I've never looked into Skia in-depth (I like cairo's API better), but there's some sample code in the repo:

http://code.google.com/p/skia/source/browse/trunk/samplecode/SampleDraw.cpp

though to be honest, I tend to just look at Mozilla code that uses it, since it's usually very clean:

https://github.com/mozilla/mozilla-central/blob/master/gfx/2d/DrawTargetSkia.cpp
https://github.com/mozilla/mozilla-central/blob/master/gfx/2d/SourceSurfaceSkia.cpp
https://github.com/mozilla/mozilla-central/blob/master/gfx/2d/PathSkia.cpp

... and it is.

Bondematt
Jan 26, 2007

Not too stupid
A month or two ago I had posted with some physics issues I was having with colliders in Unity. Turns out that I needed to keep the gameobject inactive until I had all its colliders added, not really sure why though.

The scene:
1) Player is created in editor. Has a rigidbody and a boxcollider
2) Instantiate a shipObject that is inactive. Has a rigidbody.
3) Generate a visible mesh based on a list of tiles the ship contains. Issue occurs even if I don't generate this.
4) Instantiate gameObjects with colliders based on the tiles and set the shipObject as their parent. This combines the tiles along the same plane into one larger collider, creating one collider per wall/deck so I don't up with with all 2500 tiles having their own child object with a collider.
5) Calculate and set center of mass based on the tiles position. I am not modifying the tensor here, and just letting unity figure it out.
6) Activate shipobject

New issue:

When the first collision occurs between the player and the shipObject the ship reacts to the impact, but as soon as the collision ends the ship stops like the velocities were immediately zeroed or the drag was infinite. Then once the player object is far enough away, about 5m, the ship object will start moving like it should have been. After this first time all future collisions and physics simulation seems completely normal.

am I missing something in how colliders should be handled here?

What is even weirder is if I add a cube with a collider/rigid to this scene I get the same behavior. No script is interacting with that new object. So I broke physics somewhere I guess.

In a new project using the same player movement code, everything works normally when colliding with a cube with a collider/rigid.

Bondematt fucked around with this message at 16:55 on Mar 22, 2013

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
So what version of Futile for Unity should I be downloading? I know it's in active dev and he doesn't update the Master all that often but even in the Development branch it seems as if he hasn't updated Futile.unitypackage in seven months. Is there some other place where he posts updates? I couldn't find anything like that on his Reddit account.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Yodzilla posted:

So what version of Futile for Unity should I be downloading? I know it's in active dev and he doesn't update the Master all that often but even in the Development branch it seems as if he hasn't updated Futile.unitypackage in seven months. Is there some other place where he posts updates? I couldn't find anything like that on his Reddit account.

I grabbed the package from development branch but I agree it doesn't look different than master. I haven't seen any issues yet from doing so.

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
Yeah that's strange. Maybe I'll just contact him myself.


And while going through those Futile tutorials I saw him using Glyph Designer and TexturePacker which seem like really nice, useful tools. Can anyone speak to those and anything like them?

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Yodzilla posted:

Yeah that's strange. Maybe I'll just contact him myself.


And while going through those Futile tutorials I saw him using Glyph Designer and TexturePacker which seem like really nice, useful tools. Can anyone speak to those and anything like them?

TexturePacker is amazing for workflow. You drag things onto it and then hit publish. Poof, sprites are in and all you need to do is create FSprites and pass the name. I have the free version and it'll be a while before I drop money on it since the free version does enough for me.

Glyphdesigner I haven't used but it looks really easy. I use BMFont at the moment because I just wanted some easy font quickly. If I wanted to style my fonts, I'd drop money on Glyphdesigner but that's not until much later.

ZombieApostate
Mar 13, 2011
Sorry, I didn't read your post.

I'm too busy replying to what I wish you said

:allears:
I want to generate planets for a game in space. From what I've seen researching, it seems like a Icosahedron Geodesic Grid is the way to go? Generating the vertices doesn't seem that difficult. Does anybody have any good resources on the rest of the process? Generating the UVs? Existing textures I can use to test? There are a bunch of images on google image search, but many of them have blank space/folding tabs for paper versions and don't look like they were intended as textures. There's mention of a way to convert a 2:1 texture like you get from NASA to the sawtooth sort of looking texture it seems you need, but I haven't found a description of it yet.

Biggz
Dec 27, 2005

Yodzilla posted:

Glyph Designer and TexturePacker ... Can anyone speak to those and anything like them?

I have used the LibGDX TexturePacker with good success, and someone has made a GUI for it.

illiniguy01
Feb 19, 2011

Sweat, Ubu. Sweat. Good paranoid schizophrenic.
Ok, I am trying to get an enemy chase the character so it is always moving towards the character. Here is the code I have:
code:
 
float angle = (float)Math.Atan(HeroPosition.Y - Stalker.Position.Y / 
   HeroPosition.X - Stalker.Position.X);
float x = MovementSpeed * (float)Math.Cos(angle);
float y = MovementSpeed * (float)Math.Sin(angle); 
Stalker.Position = Stalker.Position + new Vector2(x, y);
It's xna c#. it gets called every update. Stalker should be moving towards Hero as MovementSpeed. It doesnt seem to be working though.

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!

illiniguy01 posted:

Ok, I am trying to get an enemy chase the character so it is always moving towards the character. Here is the code I have:
code:
 
float angle = (float)Math.Atan(HeroPosition.Y - Stalker.Position.Y / 
   HeroPosition.X - Stalker.Position.X);
float x = MovementSpeed * (float)Math.Cos(angle);
float y = MovementSpeed * (float)Math.Sin(angle); 
Stalker.Position = Stalker.Position + new Vector2(x, y);
It's xna c#. it gets called every update. Stalker should be moving towards Hero as MovementSpeed. It doesnt seem to be working though.
You need better parenthesis on that calculation:
code:
 
float angle = (float)Math.Atan((HeroPosition.Y - Stalker.Position.Y) / 
   (HeroPosition.X - Stalker.Position.X));

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
There are a few things I'd note in addition to that. First, you should be using Atan2 when you're trying to compute the arc tangent of a 2-dimensional coordinate because Atan only gives you results in the 0..pi -pi/2..pi/2 range due to the tangent function looping, but Atan2 will give you -pi..pi, covering the full circular range. Second, you don't need to do angle calculations in the first place, just subtract the positions to get a movement vector, normalize it, and multiply it by the move speed.

code:
Vector2 dir = HeroPosition - Stalker.Position;
float len = dir.Length;
if (len <= MovementSpeed)
    Stalker.Position = HeroPosition;
else
    Stalker.Position += dir / len * MovementSpeed;

OneEightHundred fucked around with this message at 17:40 on Mar 24, 2013

illiniguy01
Feb 19, 2011

Sweat, Ubu. Sweat. Good paranoid schizophrenic.

OneEightHundred posted:

There are a few things I'd note in addition to that. First, you should be using Atan2 when you're trying to compute the arc tangent of a 2-dimensional coordinate because Atan only gives you results in the 0..pi range due to the tangent function looping, but Atan2 will give you -pi..pi, covering the full circular range. Second, you don't need to do angle calculations in the first place, just subtract the positions to get a movement vector, normalize it, and multiply it by the move speed.

code:
Vector2 dir = HeroPosition - Stalker.Position;
float len = dir.Length;
if (len <= MovementSpeed)
    Stalker.Position = HeroPosition;
else
    Stalker.Position += dir / len * MovementSpeed;

Okay, that works. Thanks for the advice.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

illiniguy01 posted:

Okay, that works. Thanks for the advice.

When doing 2D stuff, vectors are your best friend. There's a ton of tutorials around as well.

Azazel
Jun 6, 2001
I bitch slap for a living - you want some?
Rotations: :suicide:

I'm writing a little toy on the side and am stuck on 3d rotations. I've scoured the net for information, but there's some critical step I can't seem to wrap my head around.

Given a player object with a vector position, a vector that describes it's direction, and some rotation bits that I am uncertain of, I would like to freely rotate 360 degrees in every direction. Quaternions seem like an excellent choice for this due to no gimbal lock and the like, however, this is where my brain starts failing.

The player controls strictly state: I am rotating/not-rotating negatively/positively along my X/Y/Z axis.

How exactly, and what exactly, do I need to make rotations using the above inputs actually happen? I'm more of a learn by example kind of fellow, and I'm not sure what kind of magical numbers I need to keep moving forward here. Do I simply create a rotation parameter that is a Quaternion, and that describes all of my object's rotations? What information do I need to rotate it? Everything I've read says "you can change your object's rotation by multiplying the new rotation vs. the existing rotation to get the new orientation, order matters, etc.", but how exactly am I deriving these new rotations?

Hopefully this will be blatantly obvious to me one day, but for now I turn to some of the more experienced goons for help.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Azazel posted:

Rotations: :suicide:

I'm writing a little toy on the side and am stuck on 3d rotations. I've scoured the net for information, but there's some critical step I can't seem to wrap my head around.

Given a player object with a vector position, a vector that describes it's direction, and some rotation bits that I am uncertain of, I would like to freely rotate 360 degrees in every direction. Quaternions seem like an excellent choice for this due to no gimbal lock and the like, however, this is where my brain starts failing.

The player controls strictly state: I am rotating/not-rotating negatively/positively along my X/Y/Z axis.

How exactly, and what exactly, do I need to make rotations using the above inputs actually happen? I'm more of a learn by example kind of fellow, and I'm not sure what kind of magical numbers I need to keep moving forward here. Do I simply create a rotation parameter that is a Quaternion, and that describes all of my object's rotations? What information do I need to rotate it? Everything I've read says "you can change your object's rotation by multiplying the new rotation vs. the existing rotation to get the new orientation, order matters, etc.", but how exactly am I deriving these new rotations?

Hopefully this will be blatantly obvious to me one day, but for now I turn to some of the more experienced goons for help.

It looks like you want to have 3 vectors for the player: forward, up, and right, which I think you'd typically assign to z, y and x, respectively. Then yaw, pitch and roll as input by the player are rotations about up, right and forward respectively. So if the player presses up/down then that's pitch, so you have a rotation about the right vector. I believe then (if Quaternions work like matrices) that you can multiply the existing rotation by the new one generated from yaw/pitch/roll.

Adbot
ADBOT LOVES YOU

ZombieApostate
Mar 13, 2011
Sorry, I didn't read your post.

I'm too busy replying to what I wish you said

:allears:
If you're familiar with rotating things with matrices, it works fairly similarly. You have a quaternion for your character's current rotation. You have another quaternion that you set to be the change in rotation. Then you concatenate them together and store the result in your current rotation.

C++ code:
//This is our character's rotation.
quaternion currentRotation;
//The identity quaternion is like the identity matrix, no rotation.
currentRotation = quaternion::identity;

//This will be our change in rotation, in this case 10 radians to the left
//(assuming your y axis points up and you are using a right handed coordinate system)
quaternion rotation;
//set takes Euler Angles and makes a quaternion out of them.  You could also have an axis-angle version.
rotation.set(0, 10, 0);

//Concatenate is like matrix multiplication.  Concatenate combines the rotations.
currentRotation = currentRotation.concatenate(rotation);
When you go to render your character, you can convert the quaternion to a matrix and feed that to opengl/directx/whatever.

If you try to write your own quaternion and you look up information online, there are a few things to watch out for. Column major vs Row major matrices, right vs left handed coordinate system, which axes you picked for up/right/forward and the order you apply rotations with Euler Angles (XYZ vs ZYX vs ZXY, etc) could all make things more complicated if I remember correctly.

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