It is currently Mon Dec 09, 2013 2:37 am

 All times are UTC

 Page 1 of 1 [ 11 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Logic of Ranged attack in isometric RPGPosted: Sun Dec 12, 2010 1:13 pm
 Shake'n'Baker

Joined: Fri Feb 05, 2010 1:11 pm
Posts: 52
Location: MiddleEurope

What is the logic in determining what can be hit and what cannot? I mean missile blocking. How to make it realistic? I developed a possible way, but I believe there can be another, better way to achieve that.

Assuming we have tiles on which the walls or another static objects stand, these are also missile blockers. Of course we can have pathblokers that restrict movement but allow shooting, eg. some windows or holes in wall.
In ranged attacks these would be qualified as open space.
Let's talk about missile blokers only.

My way is to calculate straight line FROM center of the tile where attacker stands TO the target's tile center. And then, each pixel of the line (from start to end) would be checked what tile of floor is it on. If ANY of the pixels of the line intersects some tile marked as BLOCKMISSILE, the shot is blocked.
Some comments please. Do you think this could be a good logic considering such isometric tiles?
And if not, are there better ways to do that?

Top

 Post subject: Posted: Sun Dec 12, 2010 1:35 pm
 Corpse Bride

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2221
Location: England
Look at which tile the missile is starting and finishing on.

It will have some length in both the x and y directions.

Choose whichever length is longest, and divide the line trajectory into that many steps.

As you step along the trajectory, you will be stepping forwards onto a new tile row each step, but you should also calculate the sidewards coordinate and see if your projectile had moved over onto a new column in this step.

If it has, then you must look at the square you've clipped in addition to the square you've stepped onto, and determine if both of those squares are pathable.

_________________
I ain't pushing no moon buttons.

Top

 Post subject: Re: Logic of Ranged attack in isometric RPGPosted: Wed Oct 12, 2011 1:31 pm
 Shake'n'Baker

Joined: Fri Feb 05, 2010 1:11 pm
Posts: 52
Location: MiddleEurope
I was ashamed of posting on this problem of mine, cos I would possibly sound like an idiot.
I am trying to understand your tip, Jasmine, but have problem with it.
As I can remember, I never programmed a line trajectory yet.
What's that? I know only how to do the line from a start point (x,y) to an end point (x,y),
next thing I have, are tiles... whether square or isometric... it doesn't matter. The principle
is the thing I need to get into my understanding.

Here I add my illustration of what do I need to achieve. To make a line of tiles based on
a line between two points, where every highlighted tile of the "line of tiles" is made of every tile below, intersected by the pixels of the line.
Every tile of the "line of tiles" will then be stored in a linear list in form of [x,y] coordinates for other
operations to be done with it.

Is there an algorithm for that?
Or would a coordinate transformation play any role here?

_________________
Even this world is "programmed" by a Creator, the most skilled programmer of us all. What do you think of all that exists and all the environmental phenomena? He that maketh all had programmed it all and whenever needed, He can call one of the functions with input specified by Him.

Top

 Post subject: Re: Logic of Ranged attack in isometric RPGPosted: Wed Oct 12, 2011 1:51 pm
 Corpse Bride

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2221
Location: England
You can make an algorithm for it yes.

The missile has to move from start to finish tile. Calculate the displacement:

Code:
DeltaX = FinishX - StartX;
DeltaY = FinishY - StartY;

Each time the missile moves to a new grid location, it is either stepping in x or in y.

Code:
If (somecondition = True) Then
x = x + SGN(DeltaX);
Else
y = y + SGN(DeltaY);
End If

somecondition is whether the line exits the current grid location horizontally or vertically. For this you should look at the corner (cX,cY) of the tile between the two adjecent tiles, and see if the line passes to the left of right of that point. You can do this by looking at the sign of the Cross product:
Code:
CrossProduct = (cX-StartX) * DeltaY - (cY-StartY) * DeltaX

_________________
I ain't pushing no moon buttons.

Top

 Post subject: Re: Logic of Ranged attack in isometric RPGPosted: Sun Oct 16, 2011 5:21 pm
 Obfuscation Ogre

Joined: Sun Oct 16, 2011 3:09 pm
Posts: 299
Location: Here (where else?)
Suppose you want to draw a line from (x1, y1) to (x2, y2).
In x direction you need to do dx steps, where each step is divided in dy sub-steps. In y direction you need to do dy steps, where each y-step is divided in dx sub-steps. substeps is the number of sub-steps you can do each iteration. since both x and y need to do dx*dy sub-steps, they are both finished at the same time.

Code:
dx = abs(x1-x2); dy = abs(y1-y2)
substeps = min(dx, dy)
x=x1; y=y1
sx=0; sy=0
while x!=x2 or y!=y2 do
sx = sx + substeps
sy = sy + substeps
if sx >= dy:
x = x + sgn(x2-x1) # Do a step in the right direction
sx = sx - dy
endif
if sy >= dx:
y = y + sgn(y2-y1) # Do a step in the right direction
sy = sy - dx
endif
end
I think the algorithm is called the Bresenham algorithm

_________________
My project: Messing about in FreeRCT, dev blog, and IRC #freerct at oftc.net

Top

 Post subject: Re: Logic of Ranged attack in isometric RPGPosted: Wed Nov 16, 2011 11:29 am
 Shake'n'Baker

Joined: Fri Feb 05, 2010 1:11 pm
Posts: 52
Location: MiddleEurope
Thanx alot Jasmine and Alberth. From this you can see I am a programmer amateur.
If I knew anything about 'Bresenham's algorithm', it would of course not be such a problem for me.
Seems that I am missing some essential and elemental basics of programming.
That's the motivation that I'll perhaps need to delve deeper into these mysteries.
From now on, I study Bresenham's algoritm. Thanx, skilled programmers.

_________________
Even this world is "programmed" by a Creator, the most skilled programmer of us all. What do you think of all that exists and all the environmental phenomena? He that maketh all had programmed it all and whenever needed, He can call one of the functions with input specified by Him.

Top

 Post subject: Re: Logic of Ranged attack in isometric RPGPosted: Wed Nov 16, 2011 10:56 pm
 Corpse Bride

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2221
Location: England
Alberth's algorithm is better, but mine teaches you more

_________________
I ain't pushing no moon buttons.

Top

 Post subject: Re: Logic of Ranged attack in isometric RPGPosted: Thu Nov 17, 2011 2:53 am
 Harmlessness does no harm

Joined: Tue Sep 14, 2004 8:37 pm
Posts: 3913
Location: Ferriday, LA, US
Might be worth considering the way line-of-sight is done for tabletop tactical games. The basic idea is that you don't measure the line between the centers of different units; rather, you start from the corners of the spaces they occupy. If you draw lines between each appropriate point (Player1's North corner to Player2's North corner, etc.), then just check to see if any spaces between here and there are occupied (by a wall, another unit, and so on). For each line that intersects an occupied space, your "chance to hit" percentage goes down. If all four corners are blocked, 0%... if three lines are blocked, 25%, two lines 50%, one line 75%, and if all lines are unobstructed, the hit chance is 100% of the "base" chance-to-hit score.

So, for each corner of a space that doesn't reach the target square via line, you dock 1/4 of the initial chance that the projectile will land where intended.

_________________
What most people don't understand about "enlightenment" is that it is not an end-goal; but where you find yourself just before taking a new "first step."

Top

 Post subject: Re: Logic of Ranged attack in isometric RPGPosted: Mon Nov 21, 2011 12:59 pm
 Shake'n'Baker

Joined: Fri Feb 05, 2010 1:11 pm
Posts: 52
Location: MiddleEurope
Hallelujah!
Bresenham's algorithm works just fine.
All your opinions have been noted.

Thanx Jasmine and Alberth.
Jasmine: I know, and I'd like to try, but the Cross-product and "somecondition" were problems for me.
Plus, in addition, I had to deal with the fact what does SGN function mean.
In Wikipedia, I found it's called signum function and that it returns either -1, 0 or +1 from a numerical value, depending if the number is positive, negative or none (zero) - for determining direction. My programming language doesn't have it, and so I had to program a sgn function myself, which could be then called with specified input so that it could return -1, 0 or 1.

Cross-product seems very difficult for me, at least now, but maybe there exist some basics I should take before that to learn something. I had to copy-paste Alberth's algorithm, modify it for my own language and then analyse it why it is so.
My best experience as far as I know, goes from observation how does things work. Only then I can understand it.
If I have some program with script inside, I go step-by-step to ensure I understand why every line is written as it is.
Maybe it would be good to post an example script that can be executed, so that I could observe step by step...
Thanx anyway, Jasmine, you've helped me alot before.

rotInMilc: Your contribution has been well noted, red-bearded Theraje guy . An advanced system indeed. And if possible, I would apply, but it would possibly require my engine to turn from tile-based to non-tile based, wouldn't it? You meant the four corners of one tile (free or occupied), right?

_________________
Even this world is "programmed" by a Creator, the most skilled programmer of us all. What do you think of all that exists and all the environmental phenomena? He that maketh all had programmed it all and whenever needed, He can call one of the functions with input specified by Him.

Top

 Post subject: Re: Logic of Ranged attack in isometric RPGPosted: Mon Nov 21, 2011 1:53 pm
 Harmlessness does no harm

Joined: Tue Sep 14, 2004 8:37 pm
Posts: 3913
Location: Ferriday, LA, US
And if possible, I would apply, but it would possibly require my engine to turn from tile-based to non-tile based, wouldn't it? You meant the four corners of one tile (free or occupied), right?

It wouldn't require you to change the system you have currently, no. The basic idea is that you project a path from the corners of the "origin" tile to the corresponding corners of the "target" tile. For each path that intersects an occupied tile between the origin and target, you take away 1/4 of the "visibility" of the target, and thus the likelihood of connecting the attack successfully.

In fact, this system would use Bresenham's algorithm, it simply uses it in a more accurate (but admittedly more complex) manner. If you are familiar at all with the concept of raycasting (a la the rendering method used in Wolfenstein 3D, and DOOM), the premise is identical -- stop the path whenever it intersects a blocked tile, and act accordingly (in the Wolf3D/DOOM case, draw the wall; in our case, subtract 25% from the chance of your attack hitting its intended target).

_________________
What most people don't understand about "enlightenment" is that it is not an end-goal; but where you find yourself just before taking a new "first step."

Top

 Post subject: Re: Logic of Ranged attack in isometric RPGPosted: Mon Apr 15, 2013 6:33 pm
 Level 1 Cleric

Joined: Thu Apr 11, 2013 9:27 pm
Posts: 12
Location: Kansas
How would this take in account a damageable object between point a to b? I plan to have destructible objects and I am curious on if you would still decern it as a "shot blocker" or would be something completely different?

_________________
“Man is still the most extraordinary computer of all.” – John Fitzgerald Kennedy

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 11 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: No registered users and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ Forums    Forum Rules and Posting Guidelines Wiki Discussion    Help    Content Issues Game Programming Discussion    C and C++ Game Programming    Java Game Programming    Language Agnostic Programming    .NET Game Programming    VB Game Programming    Mobile Game Programming    Web-Based Game Programming    Other Languages    OpenGL Development    Direct X Development Game Development Discussion    Game Design    Game Media Off-Topic Discussion    Announcements    Off-Topic    Community Projects    News