A custom Room Viewport, Autotracking not working how intended

Started by Olleh19, Wed 28/10/2020 11:20:48

Previous topic - Next topic

Olleh19

I'm guessing i need to set something else, to make the room scroll only via X perhaps. Since if i let go of the

Code: ags
 
 
   Game.Camera.SetAt(5, 4);
  


in RepExec it just rearanges the room wrong again, once autotracking is enabled. It's a sidescroller so the room should eventually go downwards sorta like if you were using an elevator, but i'm guessing the scrolling has to be done manually for this entire room. So the X cordinate for when it should be able to scroll Y again is around 700. It's a very wide room. I just need to get a feel for how to work the custom cameras.

I've tried a bunch of things and none of them work. Forexample i thought i could change the x, value and have it go x++; when the player reaches and ends certain spots. But it did not work out as anticipated. (laugh)

All my scroll attempts ended up with a bump to the new cordinates looking aweful.


Crimson Wizard

#1
Please clarify what are you trying to do, I guess you want to scroll the room but how? What does "Autotracking not working" mean, what did you expect and what happened?

Olleh19

Quote from: Crimson Wizard on Wed 28/10/2020 12:36:33
Please clarify what are you trying to do, I guess you want to scroll the room but how? What does "Autotracking not working" mean, what did you expect and what happened?

What i mean is, autotracking does "work". But i'm expecting it to auto follow the character in the newly set room camera code, that is in the repeatedly_execute() function. Is that making it clearer to you? Would be neat if that worked, but ofc not  (laugh)

What happens is once autotracking is enabled. It just goes back to "normal room settings when you import the image into AGS" type of look, which is wrong, hence i've tried to play around with the camera to get it right (which it is, with that code above). But once that code is set. How do i make the room scroll to the sides like normal AGS behaviour would if the image was larger then 320 - 200px. Without it resetting itself? That is what i'm wondering.

And the question after that would be, say the room then after  x>700 goes downwards, then the cameras needs to be changed once again, so it instead scrolls downwards. Yes, it's complicated. But it would be neat to know how to change the camera very much to ones liking, for cutscenes, and such! (nod) and before you say read the manual. That's all i try to do everyday when i use this Editor. F1 is my second best friend, or "autofill" feature of AGS, Best friend is you guys!

Crimson Wizard

#3
Quote from: Olleh19 on Wed 28/10/2020 14:35:16
What i mean is, autotracking does "work". But i'm expecting it to auto follow the character in the newly set room camera code, that is in the repeatedly_execute() function. Is that making it clearer to you? Would be neat if that worked, but ofc not  (laugh)

No, I am afraid I still don't understand... what do you mean by that?

For example, the code you posted above
Code: ags

Game.Camera.SetAt(5, 4);

This code locks camera at room's x=5, y=4. It won't scroll like this, it will stay locked at the exact coordinates that you provide. Were you expecting something else? Why did you use this code and these parameters, what's their meaning to you?


Could you try explaining what you are trying to achieve in simple language, without refering to code? Like, you want camera to follow after character, but not like default ags, and do ... what instead?


EDIT: ok... a blind guess, are you trying to make camera follow character, but positioned always with few pixels offset?

Olleh19

Quote from: Crimson Wizard on Wed 28/10/2020 15:11:55
Quote from: Olleh19 on Wed 28/10/2020 14:35:16
What i mean is, autotracking does "work". But i'm expecting it to auto follow the character in the newly set room camera code, that is in the repeatedly_execute() function. Is that making it clearer to you? Would be neat if that worked, but ofc not  (laugh)

No, I am afraid I still don't understand... what do you mean by that?

For example, the code you posted above
Code: ags

Game.Camera.SetAt(5, 4);

This code locks camera at room's x=5, y=4. It won't scroll like this, it will stay locked at the exact coordinates that you provide. Were you expecting something else? Why did you use this code and these parameters, what's their meaning to you?


Could you try explaining what you are trying to achieve in simple language, without refering to code? Like, you want camera to follow after character, but not like default ags, and do ... what instead?


EDIT: ok... a blind guess, are you trying to make camera follow character, but positioned always with few pixels offset?


Exactly, it's locked. It should be locked, until the player moves to either RIght or Left side ends of the sides. Just like a normal untouched camera room would react.

This is quite funny. I am so dumb with words since English is not the native language.

I want the room to scroll to the sides like normal AGS behaviour after that code is set. How can this be so hard to explain. Damn it!  (laugh) and i THOUGHT in my mind that Autotracking would enable that

EDIT: I'm drawing pictures to demonstrate instead.

EDIT: Sorry imgur is giving me errors the low resolution probably fucks it up........It will not upload the pictures drawn in 240-320px, or such. At least not for me. and zoom image do not recognise the links.................... (laugh)


The fixed code version is how it looks after pushing F5 which is exactly right, but then it's locked. It needs to able to scroll to the sides, and keep it's "locked Y" Setting.........

This is how the room looks IMPORTED in AGS when pushing F5 (not teh room just a visual demonstration).

Image 1: http://www.mediafire.com/view/1y6sga1jnavjjk3/AGSEDITOR.png/file


Room is "fixed" with code, so everything that should be seen is seen in the Camera view.

IMAGE 2: http://www.mediafire.com/view/p0m55ecq6r8xrn7/AGS2.png/file#


Olleh19

Quote

Could you try explaining what you are trying to achieve in simple language, without refering to code? Like, you want camera to follow after character, but not like default ags, and do ... what instead?


The camera should follow the character like it would in a normal room situation, but with the difference that the Y settings (that is locked, yes i know X is locked too). X needs to get unlocked so room scrolls normally to the sides.

Like if the game was 320px wide..ok I import a image that is 6000px wide? What does AGS do? It scrolls to the sides! Do you understand now?  :)

If i don't lock the room i get the look of IMAGE 1!


Crimson Wizard

#6
Quote from: Olleh19 on Wed 28/10/2020 15:48:45
The camera should follow the character like it would in a normal room situation, but with the difference that the Y settings (that is locked, yes i know X is locked too). X needs to get unlocked so room scrolls normally to the sides.

Now I probably do understand. You want camera to be locked at certain Y coord, but follow the character changing only X.

This can be done like this for example:
Code: ags

Game.Camera.SetAt(player.x - Game.Camera.Width / 2, 4);



But from previous posts, you also want camera to only move if player reached leftmost or rightmost camera edge?

Olleh19


Olleh19

HALLELUJA there it was! But now when he reaches the end it should be able to scroll downwards too.
You don't need to give me exact numbers, just a basic idea. Then i keep fiddling with it!

But ONLY after x>700 thats where the RED LINE is drawn on the image, and teh room starts going downwards, as you can see it's going downwards in an angle, but i don't think the angle "matters" to the code that much?
It's just the fact that it should be able to scroll down after the 700px reach of the character.


Edit: BTW, these kind of settings. Where are they in the manual? I wished i could find em  (laugh)

Edit: Changing it to height, trying around here. Getting some strange, yet intresting results ! (laugh). Maybe this is a case where i would need more Cameras as the manual talks about being possible.

Code: ags
function room_RepExec()
{


{


  Game.Camera.SetAt(player.x - Game.Camera.Width / 2, 4);

 if (cAxl.x>700 && cAxl.y>203)
 {
     Game.Camera.SetAt(player.x - Game.Camera.Width / 2, 4);
Game.Camera.SetAt(player.x - Game.Camera.Height / 2, 90);


 }

}
}


Well things certainly change when reaching the destination now, not to it's intention (Scroll downwards after x 700 and y 203) tho, but at least something! Close but no cigar, as of yet. Just guessworking here.

Crimson Wizard

#9
If camera should be going along diagonal line, then you need to change both x and y parameter in SetAt.

For the example, centering camera on player's feet is: "Game.Camera.SetAt(player.x - Game.Camera.Width / 2, player.y - Game.Camera.Height / 2);".
You may adjust this to add offsets or limit these values.

If your camera's line can be described with a function, then you may take one coordinate from player's position and calculate another using this function. Only subtract starting position from x (or y), like 700 in your case.
Again, simply an example:
Code: ags

int x = player.x - Game.Camera.Width / 2;
int y = (x - 700) + 10; // a simple linear function
Game.Camera.SetAt(x, y);



For the general case, if the camera must move strictly along certain line, then one could build a normal vector (perpendicular) from player's position to that line and find coordinates where these lines cross.
But this may be too much for your case (if it's only one room). If all your game is like this, then perhaps its worth writing such general algorithm.


I'm afraid I cannot explain this all in detail now, as I am very tired today and my head not working well too. I hope someone like Khris can join this topic :).

Olleh19

Quote from: Crimson Wizard on Wed 28/10/2020 17:48:38
If camera should be going along diagonal line, then you need to change both x and y parameter in SetAt.

For the example, centering camera on player's feet is: "Game.Camera.SetAt(player.x - Game.Camera.Width / 2, player.y - Game.Camera.Height / 2);".


In general, if the camera must move strictly along certain line, then one has to build a normal vector (perpendicular) from player's position to that line and find coordinates where these lines cross. But this may be too much for your case (if it's only one room).
If all your game is like this, then perhaps its worth writing such general algorithm.

I'm afraid I cannot explain this all in detail now, as I am very tired today and my head not working well too. I hope someone like Khris can join this topic :).

Don't worry my friend(!). Take the rest of the day off! This is not the game of the year i'm working on here....
Actually, it was in the 90's, i'm quite sure  (laugh) I'm trying to recreate a classic, so that in the future a different (let's put it that way) type of game could be done in AGS aswell. It's been requested before in the beginners section. Myself included, and eventually i thought let's dive into it, and see where it get's me. I hope the drawing don't spoil it.............. (laugh). Yes, let's hope he shows up! Poor Khris, always get's to do that hard work in beginners technical questions (laugh)


Edit: The last synthax that you gave, make it look reasonable ok. So it's close. I need to figure out what his Y position should be so the camera doesn't "jump" there when he reaches the 700 & whatever Y it should be. I'm again just shooting in the dark, guessworking.


Crimson Wizard

#11
I forgot to add this example in my last post:

If your camera's line can be described with a graph function (remember school, y = 2x + 10, and so on), then you may take one coordinate from player's position and calculate another using this function. Only subtract starting position from x (or y), like 700 in your case.
Again, simply an example:
Code: ags

int x = player.x - Game.Camera.Width / 2;
int y = (x - 700) + 10; // a simple linear function
Game.Camera.SetAt(x, y);

Olleh19

Quote from: Crimson Wizard on Wed 28/10/2020 17:54:46
I forgot to add this example in my last post:

If your camera's line can be described with a graph function (remember school, y = 2x + 10, and so on), then you may take one coordinate from player's position and calculate another using this function. Only subtract starting position from x (or y), like 700 in your case.
Again, simply an example:
Code: ags

int x = player.x - Game.Camera.Width / 2;
int y = (x - 700) + 10; // a simple linear function
Game.Camera.SetAt(x, y);


Thank you very much! I have a lot to process and trial & error, but it feels nice to see the room scroll downwards, it's a win just that!

Edit: What's sad tho is one issue, brings up another one i'm using Keyboard Movement 102 i probably need to change. Why? The character start stuttering while moving upRight or DownRight, , DownLeft, etc etc.
He has always been slower or acting a bit strange when going "sideways". But it was very noticeable now when the room starts scrolling it affects him very badly, unfortunaly.

I'm using Movementlinkedtoanimation = false, all modules i've tried seems to be in love with that other mode, that no matter what settings i use, always ends up looking very bad.
Just talking about "looks" here. Perhaps linkedtoanimation is "the best" alternative.






Snarky

Instead of room_RepExec(), try creating a late_repeatedly_execute_always() function in your room script and placing the viewport positioning code there.

Olleh19

Quote from: Snarky on Thu 29/10/2020 07:26:27
Instead of room_RepExec(), try creating a late_repeatedly_execute_always() function in your room script and placing the viewport positioning code there.

!!! Thank you very much Snarky! AGS is a mystery sometimes to me, but that made the stuttering disappear. VERY cool(!)

Crimson Wizard

Quote from: Olleh19 on Thu 29/10/2020 10:03:02
!!! Thank you very much Snarky! AGS is a mystery sometimes to me, but that made the stuttering disappear.

Explanation of various repeatedly_execute functions is here: https://github.com/adventuregamestudio/ags-manual/wiki/RepExec

repeatedly_execute_always is run before game updates itself, which means it will be always 1 step behind (all properties have values from last update). This function is still useful to adjust some things before game updates, if you want to affect that update.
late_repeatedly_execute_always is run after game updates itself, which means it will access up-to-date property values. This function is useful if your code is relying on current game state.

Olleh19

Quote from: Crimson Wizard on Thu 29/10/2020 10:36:27


Explanation of various repeatedly_execute functions is here: https://github.com/adventuregamestudio/ags-manual/wiki/RepExec

repeatedly_execute_always is run before game updates itself, which means it will be always 1 step behind (all properties have values from last update). This function is still useful to adjust some things before game updates, if you want to affect that update.
late_repeatedly_execute_always is run after game updates itself, which means it will access up-to-date property values. This function is useful if your code is relying on current game state.

Thanks for the update on that! Very much appreciate this guys! I thought i was doomed there for a second! (laugh)


SMF spam blocked by CleanTalk