Giving your game that extra "oomph" can really improve the experience. As games are mainly an interactive medium, interacting should feel good. Giving the player good and satisfying feedback on their actions makes the players enjoy the game more, so they'll play more!
Here are some examples on how to add a little polish to your game:
Screenshake
We'll start of with one of the most used polishing techniques in recent years. The notorious screen shake/ camera shake.
As I've already done a tutorial on the subject, I'll just post the link. I just wanted to inform you that the screen shake created in that tutorial is perfectly suited to be integrated in the scripts made in this tutorial series.
Screen-shake in Unity3D
Knockback
In some of the tutorials, I've already explained this mechanic, but if you haven't read those I'll explain it here.
Knockback is the act of pushing an object back after, for example, an attack connects. This gives the action a lot more visible power. You hit that enemy hard enough to knock him backwards, it feels much more powerful than just ticking away at a health bar.
// Knockback
[SerializeField] private float knockbackForce
private void Knockback(Vector3 damager)
{
Vector2 direction = new Vector2 (damager.x - transform.position.x,damager.y - transform.position.y);
myRigidbody.AddForce(direction * -knockbackForce,ForceMode2D.Impulse);
}
With this code, the thing getting hit will be knocked back from the thing that damaged it, referred to as "Vector3 damager".
Sound
Adding sound effects and music can make or break a game, so be very careful with what you're doing here. If done wrongly, by for example using very bland stock sound effects and music, you can ruin a perfectly good game by utterly destroying the feel. Though if done correctly it's worth every little bit of risk and can create a great experience.
Unfortunately I'm not really experienced with actually creating great sound effects and music. I'm learning, but for now I have people that do it for me, which is also a great tip. There's nothing wrong with asking for help if you're unable to do a certain thing. Even if neither person knows how something works, it's much easier to figure something out whilst working together.
Changing Colors
While something being knocked back is a good start for indicating whether or not something just got hit, you can do much more to make it more clear that, you just hit that thing. Briefly changing the color of an enemy you just hit is the method I'll be explaining now.
This method is one that has been used since the olden days of video gaming, way before fancy graphics and ragdoll physics and even screenshake became a thing.
public bool alive = true;
[SerializeField] private MeshRenderer[] model; // This is where you put all the game objects connected to your enemy that contain a material component.
private float swapTime; // This is the time the enemy stays the current color before reverting back to normal.
// The rest should be pretty self-explanatory.
void Update ()
{
if (Time.time >= swapTime && alive)
{
for (int i = 0; i < model.Length; i++) // This is just for when a model has multiple materials attached to different pieces in the model. Can also be used to your advantage when you only want certain pieces of your model to change color.
{
model[i].material.color = Color.white;
}
}
}
void Death ()
{
alive = false;
for (int i = 0; i < model.Length; i++)
{
model[i].material.color = Color.black;
}
}
public void Damage ()
{
for (int i = 0; i < model.Length; i++)
{
model[i].material.color = Color.red;
}
swapTime = Time.time + 0.5f;
}
As you can see, this script also changes the enemy's color to black when it dies. This is also a great application of this technique as it makes it easier for players to see whether or not they should be wary of an enemy because it's alive, or rest easy because it's dead.
Blinking
Like changing colors, having an object blink is another ancient technique salvaged from the great game developers of old. Back then it was used to create a fake sense of transparency, as that was not a thing available to them, but by making a sprite blink on and off extremely rapidly it would look as if it were transparent.
It can be used in the same way as changing colors, but has generally been used to indicate invulnerability for a certain period. As such I recommend using it when the player has been hit so they know they have to move to a safer location.
It looks pretty damn cool, so here's how you do it:
[System.NonSerialized] public bool hitInvul = false; // Is the player currently hit?
public float hitInvulTime = 10f; // The amount of time a player stays invulnerable after being hit.
[SerializeField] private SkinnedMeshRenderer model; // The player model.
private float blinkTime; // The time between each blink.
private float currentInvulTime = 0f; // The Time.time at which the player is no longer invulnerable.
void Update ()
{
if (hitInvul)
{
if (currentInvulTime <= Time.time)
{
hitInvul = false;
}
if (blinkTime <= Time.time)
{
model.enabled = !model.enabled;
blinkTime = Time.time + 0.05f;
}
}
else if (!model.enabled)
{
model.enabled = true;
}
}
public void Damage ()
{
blinkTime = Time.time + 0.05f;
hitInvul = true;
currentInvulTime = Time.time + hitInvulTime;
}
As you can probably see, the code basically just rapidly turns the model on and off. Overall the code looks pretty similar to the color changing one, except for the blinking part. Though you can also use the blinking loop used here for making colors blink.
There are of course a lot more different techniques for polishing your game, but these are all I'll explain for now. I recommend and encourage a lot of experimentation and exploration so you'll be able to discover and create new techniques of your own!
If you're more interested in game feel, I recommend watching this video, as it may serve as a great source for inspiration:
https://www.youtube.com/watch?v=AJdEqssNZ-U
Geen opmerkingen:
Een reactie posten