Firing bullets at a hero who is moving with a constrained X position
Hi,
I'm working on a game where my hero moves right in a side scrolling top-view game, but I am constraining his X position so that he does not move across more than half the screen. I give the effect that he's moving right by making the background scroll left, as long as my hero is moving right. As a side note, my hero is able to move left, but the background does not scroll in that case, and my hero can touch the left side of the screen. So what I've described above gives the impression that my hero can only make progress by moving to the right. When my hero is moving right, I have enemy actors that appear from the right (positioned above or below my hero on the Y-axis) and shoot bullets at him. The bullets have a behavior to move towards the position of the hero. The enemy actors continue to move left passed my hero, as long as my hero is moving right.
Here's the challenge I'm running into. When my hero is moving right and he's reached the constrained position X (but it still looks like he's moving right because the background is scrolling left), when the enemy actors appear and shoot at my hero, since my hero is constrained at a certain X position, the bullets will always hit my hero, even though there's the appearance that he's moving right and should theoretically be able to dodge the bullets. Of course, I understand that the moving background only gives the impression that my hero is moving to the right and has no effect on the bullets fired by the enemy actors. But, I'm at a loss as how to make it seem like the bullets should miss my hero because he's "moving" to the right and should not be hit because the bullets were targeted at a position that is now "behind" my hero.
I hope this makes sense. Does anyone have any thoughts? Just want to add that constraining the X position was the only way I knew to make it so that my hero did not walk off the right edge of the screen, while also making it seem like he was progressing to the right. The constrain camera didn't do the trick.
Thanks!
Comments
When your hero reaches the cutoff I imagine you'd need to start tracking the background and use it as a reference point. Tracking the difference between it and your hero and creating a faux firing point.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
@The_Gamesalad_Guru - That's really an interesting suggestion. A few questions on that.
1) Would the tracking need to begin not only after my hero reaches the cutoff, but also at the time the enemy actor spawns a shot?
2) Would this approach work if I have multiple enemy actors on the screen at the same time, each firing shots? I'm wondering if there need to be separate tracking attributes for each enemy/shot?
3) If my hero can move on both the X and Y axis, would this approach still work if I'm using the background as a tracking reference?
Thanks!
Well that's a broad question but I would start the tracking when the hero stops actual movement and the background takes over. Second as to the firing you should add some randomness anyway to your enemies. Having perfect aim is not realistic. See my video on AI and I show some examples on how to make random firing.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
@The_Gamesalad_Guru- thanks for your help. Can you tell me where I can find your videos?
Click the link in my forum signature below.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS