Collision Detection, Part 1

November 19, 2009

For the past few weeks I have been working on the plaforming elements that will form the basic construct of my character interaction with the environment I wish to create. Collision detection is one of the main principles I have to get working, and it’s crucial to the engine my game will run on. Without collision detection, I do not have a floor or walls, and I can’t design even the most basic physics.

It’s a complicated process, and even if I immediately understood the maths behind it, it still would not be a particularly easy function to craft, as I have found out. There are a few ways of doing it, and I have progressed forward a little but am still not even close to what I expect my final build to look like.

My first experiments with collision detection have been using a function in flash called OnIntercept.

I have been working with Adam Jaggard in creating a more robust engine that did not cause as much slow down on the frame rate.

Platforming Code, Ver. 1.0

November 17, 2009

Check this out:

function moveHero(event:Event):void
{
//here is my running code
if (leftDown == true) {
backdrop.x += speed;
if (speed <= maxspeed && speed >= 0){
speed += 0.2
} else if (speed <= maxspeed && speed <= 0){
speed += 1
}
} else if (rightDown == true) {
backdrop.x += speed;
if (speed >= maxspeed*-1 && speed <= 0){
speed -= 0.2
} else if (speed >= maxspeed*-1 && speed >= 0){
speed -= 1
}
} else {
backdrop.x += speed;
speed -= speed/5
if (speed<=0.2 && speed>=-0.2){speed = 0}
}
//here is my jumping code
if (upDown == true && onGround == true)
{
jumping = true;
}
if (jumping == true)
{
jump();
}
}

function moveHero(event:Event):void{ //here is my running code    if (leftDown == true) {        backdrop.x += speed; if (speed <= maxspeed && speed >= 0){ speed += 0.2 } else if (speed <= maxspeed && speed <= 0){ speed += 1 }    } else if (rightDown == true) {        backdrop.x += speed; if (speed >= maxspeed*-1 && speed <= 0){ speed -= 0.2 } else if (speed >= maxspeed*-1 && speed >= 0){ speed -= 1 }    } else { backdrop.x += speed; speed -= speed/5 if (speed<=0.2 && speed>=-0.2){speed = 0} } //here is my jumping code    if (upDown == true && onGround == true)    {        jumping = true;    }    if (jumping == true)    {        jump();    }}

Chapter Titles

November 15, 2009

So I haven’t actually deciding what my games name will be yet, but I have a good idea as to how I plan to lay out the chapters. Each of my chapters will have a seperate title, unrelated to each other apart from the elements they draw from. Each title will be taken from the mythological influence of the chapter, so for example the Japanese inspired chapter is based on the element of fire, so I have done a little research into names I like and I found this: Seika, which means ’sacred fire’. I like that a lot!

These are, of course, open to change. Here is the order, dictated mainly by the elements, but nicely fitting into a chronological narrative:

  1. Water: Greek
  2. Earth: Chinese – Earth
  3. Air: Medieval
  4. Fire: Japanese
  5. Aether: Hinduism

The Chinese chapter shall be called 土, which is pronounced ‘Tu’.

Earth

Tu means 'earth' in Chinese

The Japanese chapter shall be called Seika:

Seika

Seika means 'sacred fire' in Japanese.

Practice Visuals

November 15, 2009

I just dragged out my digital pad so I could try my hand at layering colours together in Photoshop to create an image. I’m just being playful here, to see how well I can produce drawings an images ‘freehand’.

Earth Levels: Cave

Perspective

November 15, 2009

My next post will be on the perspective that you view your character.

I have already decided to make the game 2d, as that de-complicates the process of design for me and makes the engine I will be building feasable.

 

A trick that is used in Mirrors Edge 2d is the use of a very slight perspective tweak upwards, so that the ‘2d camera’ appears to be capturing a small amount of the floor. This professionally produced Flash game gets a lot of things right, and this floor trick can help make awkward collision detection look a lot smoother.

This platform is less prone to looking odd than a flat plane, unless it is drawn badly.

Movement Maths

November 15, 2009

It’s very easy to code movement in Flash as there are many ways that I am able to do it. Unfortunately, not all of these ways are particularly effective, and some of them hinder other parts of the game coding. When I first started coding my Steampunk inspired interactive narrative, Dirt, I experimented with different ways of coding movement.

At first, with a terrible lack of foresight, I attached the arrow keys to the x and y coordinates of a movie clip which was acting as the character. This was fairly simple to do, and I was able to make a floating orb move around the screen. Something like:

on the event that -> is pressed, movie.x = (movie.x + 1)

Of course, this means that there could be no friction applied to the movement and things like gravity and jumping would not be able to do as I was merely adding directly to the movie.x and I would have to rethink the way I was coding the movement. I also had the problem of my movie clip merely flying out of the boundaries of the screen, as they could travel anywhere.

As I learned more, I decided to create a ’speed’ variable, which would measure how fast the movie was moving. This meant that I could create a slower build up of speed merely by adding incremental additions until it hit a max number.

speed = 0
on the event that -> is pressed, speed = (speed + 1)
on the event that speed > max speed, speed = (max speed)
movie.x = movie.x + speed

I can also apply a cool down to the speed variable, which would mean that when the direction button is not pressed, the movie would automatically slow down to a halt. I can do this with an else command, to make sure it doesn’t affect the character when it’s moving. I also decided to fix the problem with the movie clip running off the screen by applying the speed variable to the background.

It occurs to me that there may be some problems with the logic if I don’t keep the movie clip inside the background, when it comes to interacting with the environment, but I do not know how C# works yet so I can run this all as a maths test above anything else.

Using this same line of maths, I can create a gravity variable to apply to the character. This would then add a gravitational pull on the character. I did not mind mixing the gravitational pull with the y velocity variable this time as it meant that, merely by adding a large amount to the upwards speed variable it would create a natural jumping curve. Of course, I would not need a cool down time as gravity would apply this normally.

Character Movement

November 14, 2009

I have been considering character movement today, and I hope to implement a basic platformer code by the end of tomorrow that will allow me to overlay a character onto so I can start testing.

Prince of persia character sprites.

Original sprites from Prince of Persia.

Obviously, I have to think forward to my FMP when I design the movement controls, so I will be setting up an Xbox Controller with my PC and using that to test the characters movement. I hope to emulate the movement feel of other puzzle platformers like Prince of Persia and Another World, which originally used rotoscoped animations. I have researched the development of this style and there are still slightly more recent examples like Abe’s Odyssey.

One thing I noticed and did not like in the earlier games was the jumping mechanics, which often seemed somewhat sluggish and had the player timing their button pressing earlier so they didn’t just run off the edge. This was due to a little pre-animation of the character pushing off before the jump, which made the animation run a lot more smooth but presented what I consider to be an unneeded frustration. Abe’s Odyssey made improvements here, but I think I will test this idea of a pre-animation to make sure it works.

Another important introduction into platformers that these games made was the idea of friction. A lot of games prior to this addition allowed the character to stop dead or even turn back on themselves almost instantly. With friction included, the game controls feel more natural and it also presents a bit of a challenge in particularly back-and-forth levels. It is a little extra work, but I shall definitely be coding friction into my engine for these reasons. The addition of friction also means I can make it a variable, and change it depending on what materials the character is interacting with. This means I could create icy platforms that the player slips on, or sticky floors that slow the character down. It’s not massively important, but it ties in nicely with my concept of material properties.

Xbox 360 Controller

I will be using the Xbox 360 controller

The Xbox controller has 10 buttons and three separate directional axis. These buttons include the four coloured circles on the right side, which are useful for commands and context sensitive actions, the two white buttons each side of the center which are commonly reserved for menu or pause controls, the two trigger buttons which are often used contextually to control the trigger of a weapon, or the accelerator of a car and finally, the two bumper buttons which are intrinsically connected to the function of the trigger (such as a reload function).

In my platformer there will be a split between character control and environment control, with a possibly connection between the two that I hope to test in the engine, so I can figure out what feels best. I think one of the aims of function design is to create as little complication as possible while still allowing for challenge. As this is a platformer, I only have to worry about the 2d axis, which means my character can only travel in the variables between x and y. This means I only need one of the two analogue sticks for character direction. This will likely be the left analogue stick, as this is a popular convention in platforming and will feel more natural to anyone who has played these types of games before (which is the overwhelming majority of my user base).

This means I have eight directions to take input from:

  • Left/Right: Will be reserved for choosing which direction the character moves in.
  • Down: Will be a stationary crouch/crawl.
  • Left/Right and Down: A moving crouch/crawl.
  • Up: Possibly for initating climbing walls or ladders, with all movement directions available once you’re attached.

I will also need to apply a jump command if there are going to be gaps in the platforms for my character to cross. I considered attaching jump to the Up on the analogue stick, there are many examples of this being applied in older games (and the Wii game Super Smash Bros: Brawl) but with an analogue stick I have personally found, when this is implemented, it feels slower and less accurate. For that reason I shall be applying the jump command to the A button, as that is often the main control out of the four coloured buttons.

This movement configuration is pretty basic and should be easy to pick up very quickly. It leaves me with the four shoulder buttons of the Xbox Controller, three of the context buttons and two directional axis, with the two control buttons reserved for pause/menu to fit convention.

Colour Palette: Fire

November 13, 2009

Using Kuler, I have collected a number of fiery colours that I can use as a palette when I draw out the background and levels of the Fire chapter. This way I can keep a consistant feel and style for the entire chapter.

Colour Palette: Fire

I actually hope to blend the styles of the Earth levels into the Fire levels, as there is going to be a somewhat circular progression of colours and levels, to the point that some of the later levels are reconstructed versions of the originals.

Colour Palette: Earth

November 13, 2009

Using Kuler, I have collected a number of earthy colours that I can use as a palette when I draw out the background and levels of the Earth chapter. This way I can keep a consistant feel and style for the entire chapter.

Colour Palette: Earth

Sound

November 12, 2009

I have had a very generous offer from my friend Joe McDonald, who has suggested he help formulate and work on my sound design as he is studying that at Southampton Solent and has a big interest in video games.

Sound Wave

This is the kind of funky shit he'll be adding.

I of course, was happy to accept and am glad that I don’t have to worry about that so much. Cheers Joe. Now all I need is my other friend Joe to help me code, change my name to Joe and then rocket to the moon.