Jump to content

  • Log In with Google      Sign In   
  • Create Account

HappyCoder

Member Since 28 Apr 2007
Offline Last Active Yesterday, 11:42 AM

#5283423 Should I give up?

Posted by HappyCoder on 25 March 2016 - 12:23 PM

Also, this always motivates me its own weird way




#5282902 Should I give up?

Posted by HappyCoder on 23 March 2016 - 10:09 AM

I don't have frustration in learning and developing games, despite constant discouragement. So should I give up and just turn away from all these discouragement? Maybe I'm not meant to be because people say I'm not meant to be a video game developer? Who can be a video game developer?

 

I remember when I started making games I felt a little discouraged because I saw what others could create and felt that it was out of my reach. Years later after just focusing on making simple games within my ability, I can now do the things that I thought I couldn't before. Just stick with it, your skills will improve, you can be a game developer.




#5280084 Figuring out where a projectile will go

Posted by HappyCoder on 07 March 2016 - 06:19 PM

This is a pretty tricky problem. The approach I would take would be to pick a direction and velocity, then calculate the path iteratively meaning you simulate the game forwards in time applying gravity and updating the projectile velocity etc. Do this for a few random directions then pick the one that is the best shot. You could then keep track of the best know shot from frame to frame then each frame, do the same thing but with slightly modified versions of the best current shot. If a slightly modified version improves the shot, then store that as the best shot.

You will determine the best shot based on a score. I would score it based on how close it comes to the target, and for moving targets, how much time it would take for impact. Further away shots wont score as high since it would be more likely for the target to move.

This would be a genetic algorithm approach. You could refine it by coming up with another method that can give a good initial direction and velocity, this would make it converge faster. You will also have to fine tune how much to modify the inputs each iteration. You will also need to set a max maximum time you will simulate out to.

Once you have a way to score your shots, you can set a threshold for the score. Once a shot score exceeds a threshold you take the shot. The threshold could slowly drop down each frame to ensure that the enemy eventually shoots, and once the enemy does shoot, you raise the threshold.

I may be over complicating this, but the nice thing about this approach is it pretty flexible. You could add multiple bodies with gravity and it would handle it just fine. You could also simulate moving targets assuming you could accurately predict their future position. The way you score a shot also gives you some flexibility. You could check for collision with things you don't want to hit as part of the score.

You could also reuse the same path predictor to determine if a projectile will hit the AI's ship.


#5278360 Fundamentally, how does collision work? How did it work on the NES?

Posted by HappyCoder on 26 February 2016 - 03:46 PM

There are two approaches to collision.

1. When you move the player, you check to see if the player volume would hit any object and move them to the point of contact then slide along the wall.

2. Move the player then after they moved see if they are overlapping any object. This seems to be the approach you are taking.

Each approach has their advantages and disadvantages. #2 is usually simpler to implement and works well with many dynamic objects. However, fast moving objects can pass through walls or other objects. #1 will keep objects from passing through wall, but sweeping volumes can be tricky to implement

However, you could probably get unity to work how you want without having to resort to making your own collision detection. First of all, use a character controller to move your player around. Character controllers lets you specify how much you want the player to move and it will handle collision for you.
https://unity3d.com/learn/tutorials/modules/beginner/2d/2d-controllers


#5277995 best way to write clean code

Posted by HappyCoder on 24 February 2016 - 09:13 PM

A few tips of mine

1. Don't use inheritance just to reuse code. Be sure your base class and sub class have a strong is a relationship

2. If you use class A inside class B, don't require that class B can only be used inside class A. As an example, if you have a Car class and an Engine class, don't require that the Engine can only be used in a Car. In other words, don't have cyclical dependencies.

3. Never use singletons or global state. Global variables are usually used because they an easy short term solution to problems, but you will pay for it later. Once you remove global variables you are forced to think about the design of your code more and come up with better designs.


#5276188 How could I solve edge-case death animation?

Posted by HappyCoder on 17 February 2016 - 02:49 PM

You will probably need an additional animation where the character bends over the edge. You would have to detect when the animation would put them hanging over the edge, and play the other animation in that case. As Orymus suggested, you would have to shift the position of the animation slowly to line up correctly. However, there really isn't a correct answer in this case. It really comes down to how much time you want to put into polishing details like this. Overhanging death animations is fairly common in video games and players aren't going to care that much, but those little details can add up to really improve the experience.


#5275817 HTML5 canvas game pure javascript preloader ?

Posted by HappyCoder on 15 February 2016 - 04:27 PM

I would look into javscript Promises

If you use native javascript promises you will limit your browser support. You can use this library if you want wider browser support.
https://github.com/kriskowal/q

At this point you can write a preloader function
function preloadImage(url)
{
  return new Promise(function(resolve, reject) {
    var result = new Image();
    result.src = url;
    result.onload = resolve;
  });
}
Then to preload all images you can use the 'all' feature of promises

function preloadAllImages(imageUrls) {
  var loadPromises = [];
  for (var i = 0; i < imageUrls.length; ++i) {
    loadPromises.push(preloadImage(imageUrls[i]));
  }
  return Promise.all(loadPromises);
}
Then to wait for everything, you simply do the following
preloadAllImages(allImages).then(function() {
  // game code that depends on preload goes here
});



#5275342 How do i solve this specific scene graph problem

Posted by HappyCoder on 11 February 2016 - 04:25 PM

If you need b to not scale when a scales I wouldn't parent B to A, I would just transform the anchor point on A to world coordinates every frame and place B at that spot.


#5275304 How to calculate local velocity if you know it's world velocity and local...

Posted by HappyCoder on 11 February 2016 - 12:09 PM

https://docs.unrealengine.com/latest/INT/API/Runtime/Core/Math/FRotator/UnrotateVector/index.html

FVector localVelocity = Rotation.UnrotateVector(worldVelocity);



#5275228 Clinical studies on overlooking stupid bugs

Posted by HappyCoder on 11 February 2016 - 12:18 AM

This bug once took me hours to spot. I thought I was going crazy.
if (condition);
{
   // this runs even if condition is false
}



#5275058 Physics problem

Posted by HappyCoder on 09 February 2016 - 04:44 PM

With air resistance it wont be symmetrical. Once you include air resistance into the equations it really complicates things especially if you want to take into account the projectiles shape and if it is spinning.


#5273953 Weather simulation

Posted by HappyCoder on 02 February 2016 - 04:14 PM

First off, simulating weather for a game sounds awesome. I really like that idea.

Second, I wouldn't worry too much about being super precise and super realistic. As long as the weather patterns look reasonable and aren't doing anything crazy you should be fine. Your goal should be a weather simulation that makes the game more fun. If the weather patterns make sense to the player and can be used strategically then your simulation is good.

IMHO I wouldn't start with air temperature, pressure zones, and velocities in a tight grid and try to model it like the simulations used to predict weather. I would start by identifying what you want the weather to do and write a simulation that mimics that behavior.


#5273944 Advice for a "decoupled" game engine

Posted by HappyCoder on 02 February 2016 - 03:37 PM

Switching game engines mid development will never be an easy thing to do, even if you write your code in a way to do it. I would recommend picking an engine from the start and sticking with it.

That being said, to write your game logic game engine agnostic, you will need to build out lots of interfaces. You would implement your logic using the method available on the interfaces and have concrete implementations for each environment you want to support. This would add a lot of work to the game, so again, I wouldn't recommend it. Although one benefit to this approach would be that your code with be testable. You could write unit tests around your game logic using a test implementation of the game interface. The same applies for server side logic, you could run the same game logic code server side outside the game engine.


#5273934 Gameworld structure for platformer/rpg?

Posted by HappyCoder on 02 February 2016 - 02:42 PM

I would make an list of priorities of what you want the player to experience. These may not be your priorities, but I am just putting some out as an example.

1. Exploration - the player should be excited to discover and is rewarded for exploring
2. Character progression - the player should be seeking ways enhance and improve their character
3. Mastery of the mechanics - the gameplay should have enough depth and challenge to engage even the best gamers

Your list may be longer than this, spend some time to figure what priorities you want for your game then compare them to world options or any other decision for you game.

If exploration is your top priority I would choose option #2 since an open world lets you better hide secrets and gives more freedom
If character progression is most important then #3 seems to make sense.
If mastery of the mechanics is most important then option #1 makes sense since it avoids crossing an overworld and gets straight to the action

So it really depends on what experience you want the player to have.


#5273403 How can I make a gameObject follow a path in Unity C#?

Posted by HappyCoder on 30 January 2016 - 03:56 PM

I wanted to add a few more tidbits.

First you can also have your EnemyPath component draw gizmos to make the path more visible
class EnemyPath : MonoBehavior
{
  public Transform[] path;

  public void OnDrawGizmos()
  {
    Gizmos.color = Color.green;

    for (int i = 1; path != null && i < path.Length; ++i)
    {
      Gizmos.DrawLine(path[i - 1].position, path[i].position);
    }
    
  }
}
To follow a path you have two options. You write your AI to be able to move towards a point. You follow a path by having the enemy goto the first point in the path, once it gets within a certain radius it moves to the next point.

You could also simply write a function that returns the point x distance along the path and updating enemy positions would look something like this

enemy.transform.position = enemyPath.getPointAtDistance(enemy.distance);
enemy.distance += enemy.speed * Time.deltaTime;





PARTNERS