Display a FlipBook Or Something in Isometric View

Topics regarding Scripting with Reality Factory
Post Reply
User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Display a FlipBook Or Something in Isometric View

Post by metal_head » Wed Dec 10, 2008 7:50 pm

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

Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Re: Display a FlipBook Or Something in Isometric View

Post by Jay » Wed Dec 10, 2008 8:46 pm

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.
Everyone can see the difficult, but only the wise can see the simple.
-----

User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Display a FlipBook Or Something in Isometric View

Post by metal_head » Wed Dec 10, 2008 9:20 pm

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?

Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Re: Display a FlipBook Or Something in Isometric View

Post by Jay » Wed Dec 10, 2008 9:57 pm

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.
Everyone can see the difficult, but only the wise can see the simple.
-----

User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Display a FlipBook Or Something in Isometric View

Post by metal_head » Wed Dec 10, 2008 10:11 pm

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?

User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Display a FlipBook Or Something in Isometric View

Post by Juutis » Sun Dec 14, 2008 2:54 am

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.
Pain is only psychological.

User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Display a FlipBook Or Something in Isometric View

Post by metal_head » Sun Dec 14, 2008 10:46 am

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:

User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Display a FlipBook Or Something in Isometric View

Post by Juutis » Sun Dec 14, 2008 10:57 am

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>
Pain is only psychological.

User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Display a FlipBook Or Something in Isometric View

Post by metal_head » Sun Dec 14, 2008 11:22 am

oh, I'm making the game with 0.75, I'll update to 0.76 and see if it works, thanks!

Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Re: Display a FlipBook Or Something in Isometric View

Post by Jay » Sun Dec 14, 2008 12:43 pm

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!
Everyone can see the difficult, but only the wise can see the simple.
-----

Voltare
Posts: 263
Joined: Tue Jul 05, 2005 10:36 am

Re: Display a FlipBook Or Something in Isometric View

Post by Voltare » Sun Dec 14, 2008 5:12 pm

Jay, it seems you agree with me on one thing....isometric is the BEST for rpg's........and thanks juutis!

User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Display a FlipBook Or Something in Isometric View

Post by metal_head » Sun Dec 14, 2008 7:26 pm

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.

Post Reply