Page 1 of 1

Display a FlipBook Or Something in Isometric View

Posted: Wed Dec 10, 2008 7:50 pm
by metal_head
Is it possible to make a Crosshair in the isometric view using a flipbook and a script...or oly a script. This week I'm working on a mini game, where you have a top view and this is made by an isometric camera, but I need a crosshair so I will be able to see where am I shooting.

Look at this post in my website (it's translated by google), that's what I'm talking about, see the screens :)
http://translate.google.com/translate?u ... n&ie=UTF-8

Re: Display a FlipBook Or Something in Isometric View

Posted: Wed Dec 10, 2008 8:46 pm
by Jay
If it's a top down perspective it is - relatively to a 3d or isometric view - simple. The middle point of the image has to be calculated using the sin and cos functions with the angle of the player and a given distance from the player. Then add the position of the player on screen.

Code: Select all

IMAGE_MIDDLE_X = PLAYER_SCREEN_POS_X + sin(self.player_yaw+YAW_DELTA)*CROSSHAIR_DIST;
IMAGE_MIDDLE_Y = PLAYER_SCREEN_POS_Y + cos(self.player_yaw+YAW_DELTA)*CROSSHAIR_DIST;

IMAGE_TOPLEFT_X = StringCopy(IMAGE_MIDDLE_X) - IMAGE_SIZE_X_HALF;
IMAGE_TOPLEFT_Y = StringCopy(IMAGE_MIDDLE_Y) - IMAGE_SIZE_Y_HALF;
The YAW_DELTA value depends on which value the yaw value has when the player is facing right. The goal is to make the number inside the sin and cos functions 0 if the player is facing right. If the player is already facing right when self.player_yaw is 0, then it should be 0. Normally the YAW_DELTA_VALUE should be a multiple of Pi/2. This is because 2*Pi equals a full circle, like a compass, in which 0 and 2*Pi are east. The Pi/2 would be north, Pi would be west, and 3/2*Pi would be south (or -Pi/2). The only sure way is to try it out. First use those four numbers - 0, Pi/2, Pi, -Pi/2 - as the YAW_DELTA value and then if it does not work you can go to stranger numbers.

But this will ONLY work if the view is 100% top down view. If it is only slighly isometric it would look unrealistic. If you want to use it in any camera angle possible, it will get VERY complicated, because then you will be doing some extensive 3d math - the very same the computer does for every vertex in a 3d scene.

Re: Display a FlipBook Or Something in Isometric View

Posted: Wed Dec 10, 2008 9:20 pm
by metal_head

Code: Select all

[Isometric]
; camera height above ground (in texels)
; auto adjusts height to current player actor
height = auto
; angle (in degrees) of camera above horizontal
angleup = 89.9
; angle (in degrees) of camera from directly behind
anglearound = 0
; distance (in texels) of camera from player
distance = 350
; if true the camera will move in/out to avoid obsticles
collisiondetection = true
The camera has angle of 89.9, because if I set it to 90, the camera starts to swap directions, sooo prbably it won't work, baaad. I don't know.. isn't there a way just to display the mouse on the screen or.. I don't know really...just like the menu?

Re: Display a FlipBook Or Something in Isometric View

Posted: Wed Dec 10, 2008 9:57 pm
by Jay
With unrealistic i meant it was not 100% realistic. Maybe i exaggerated a bit here. Try it with 89.9, it should work too, i meant like an angle of 85 would produce a bit unrealistic results.

If you just display the mouse you get the problem that you then have to calculate the point where you have to shoot and this would be just as, if not more complicated.

Re: Display a FlipBook Or Something in Isometric View

Posted: Wed Dec 10, 2008 10:11 pm
by metal_head
well, in the top down view, the player is rotatet by the mouse, the problem is that the crosshair is gone.

OK, so theese commands are in low-level, and I'll have to use a flipbook for this, right?

Re: Display a FlipBook Or Something in Isometric View

Posted: Sun Dec 14, 2008 2:54 am
by Juutis
I know this ain't exactly what you're after but I just have to post it. This little script draws a crosshair on the screen and lets you move it freely around the screen with the mouse. Then it calculates the angle between the crosshair and the player origin and rotates the player accordingly. Works with the built-in player:

Code: Select all

{
    deltaX      [0]
    deltaY      [0]
    
    angle       [0]
    
    Spawn[ ()
    {
        LowLevel("setup");
    } ]
    
    setup[ ()
    {
        PawnRender(false);
        MouseControlledPlayer(false);
        
        think = "run";        
    } ]
    
    run[ ()
    {
        deltaX = GetEntityScreenX("Player") - GetMousePosX();
        deltaY = GetEntityScreenY("Player") - GetMousePosY();
        
        if(deltaY = 0)
        {
            deltaY = deltaY + 0.1;
        }
        
        if(deltaY > 0)
        {
            angle = atan(deltaX / deltaY) / 0.0174532925199433 + 180;
        }
        else
        {
            angle = atan(deltaX / deltaY) / 0.0174532925199433;
        }        
        
        DrawFlipBookImage("crosshair",0,GetMousePosX()-16,GetMousePosY()-16,255,0,0,0,1);        
        SetEntityRotation("Player",0,angle,0);
    } ]
}
You'll need a flipbook called 'crosshair' in your level that contains the crosshair bitmap. It should be 32x32 pixels. For a different size you'll need to change the line

Code: Select all

DrawFlipBookImage("crosshair",0,GetMousePosX()-XX,GetMousePosY()-YY,255,0,0,0,1);
so that XX is half of the image's width and YY is half of its height.

Re: Display a FlipBook Or Something in Isometric View

Posted: Sun Dec 14, 2008 10:46 am
by metal_head

Code: Select all

if(deltaY > 0)
        {
            angle = atan(deltaX / deltaY) / 0.0174532925199433 + 180;
        }
        else
        {
            angle = atan(deltaX / deltaY) / 0.0174532925199433;
        }        
I think tere's tomething wrong here, because the console says"
run 14/10 atan Method not found
and the crosshair is not displayed.
I changed the line :

Code: Select all

DrawFlipBookImage("crosshair",0,GetMousePosX()-16,GetMousePosY()-16,255,0,0,0,1);
to:

Code: Select all

 DrawFlipBookImage("crosshair",0,GetMousePosX()-90,GetMousePosY()-90,255,0,0,0,1);
because my flipbook image is 90X90.
I named the flipbook "crosshair" and everything else should be just fine, but the crosshair doesn't show up and the player won't rotate if I'm using the script. Maybe I've done something wrong again.

oh btw, can you explain me what is this about

Code: Select all

angle = atan(deltaX / deltaY) / 0.0174532925199433 + 180;
and why there are so many digits here, I got a little confused :D :lol:

Re: Display a FlipBook Or Something in Isometric View

Posted: Sun Dec 14, 2008 10:57 am
by Juutis
Which RF version are you using? The atan command is only available in 0.76 and so this script will only work with that version.
because my flipbook image is 90X90.
Then it should be:

Code: Select all

DrawFlipBookImage("crosshair",0,GetMousePosX()-45,GetMousePosY()-45,255,0,0,0,1);
and why there are so many digits here, I got a little confused
That's just the conversion from radians to degrees. The digits are there so the value is exact enough.
Basically:
<angle in radians> / 0.017... = <angle in radians> * 57.295... = <angle in radians> / (2 * PI) * 360 = <angle in degrees>

Re: Display a FlipBook Or Something in Isometric View

Posted: Sun Dec 14, 2008 11:22 am
by metal_head
oh, I'm making the game with 0.75, I'll update to 0.76 and see if it works, thanks!

Re: Display a FlipBook Or Something in Isometric View

Posted: Sun Dec 14, 2008 12:43 pm
by Jay
Thanks Juutis. That script does exactly what i was trying to do, but didn't have the time to dive depper into the code. I was aiming for something like a point and click in isometric view, like diablo. I have to rewrite it for isometric view and not only top-down, but this is a good start. Thanks!

Re: Display a FlipBook Or Something in Isometric View

Posted: Sun Dec 14, 2008 5:12 pm
by Voltare
Jay, it seems you agree with me on one thing....isometric is the BEST for rpg's........and thanks juutis!

Re: Display a FlipBook Or Something in Isometric View

Posted: Sun Dec 14, 2008 7:26 pm
by metal_head
Yeah baby, it works GREAT! Thanks, man!

Now I have some problems with the new version (again), but I think I'll be just fine. The player moves alfuly fast and nothing slows him down, because of that, he can walk through everything and even get out f the level :lol: . But let's don't get off-topic, thanks again!

I think this thread should be one of the top threads, because a lot of people would want something like this in their games, and here the problem is solved.