Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Pages: 1 2 [All]

Author Topic: The illusion of vehicle movement across the scene (on the X-axis)  (Read 6566 times)

0 Members and 1 Guest are viewing this topic.

Indra Anagram

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 68
    • View Profile

Dear Muties!

Here I am again with another question. Like previous ones I think it is pretty much common for adventure games, so lots of people may be interested in the solution.

In "The Cat Lady" (this adventure game has recently become my huge inspiration) there is a cutscene/scripted scene with a van driving across the scene. I've made some screens and combined them in this GIF to illustrate what I mean:



What I am especially interested here is the van moving horizontally past trees and houses in the background.

1) I know there is a limitation for background resolution in WME. In the aforementioned scene the background seems to last and scroll forever. Yet since houses in the fog do repeat, I suspect the background is looped somehow. How is it possible to achieve such an effect in WME?

2) The van sprite itself is animated in a sly way: sometimes it seems not to move on the X-axis at all and other times it does actual motion from one edge of the scene to the other. Am I right?

3) The trees in the "foreground" have a kind of parallax effect. I know there is a chapter in WME tutorial about levels, yet here, like with the background, the trees seem to last forever)) How does one achieve this? Do these sprites load and unload constantly? What would the code look like? I'm afraid even to think about such code size and contents  :o

Guys, please help me to comprehend making of a complex scripted thing like this.

Thank you for your attention, thoughts, portions of wisdom and advice!

Logged
Owls are not what they seem...

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5677
    • View Profile
    • Dead:Code Site
Re: The illusion of vehicle movement across the scene (on the X-axis)
« Reply #1 on: November 25, 2017, 01:05:55 PM »

It's all smoke and mirrors :) Simply put, forget about scrolling. The van is basically staying in the same place (moving a little to the left and right) while everything else moves. For example, the trees would be "recyclable" entities, that move from right to left, and when they're off screen, they skip back all the way to the right and then move through the screen again. Same for the fog, houses etc.

Basically you'd need just one script, that would move it's owner entity by decreasing its X position, and if X is lower than some threshold, it would increase it again and repeat the process.
This trick is used by many games, both 2D and 3D. From recent memory, Life is Strange Before the Storm uses this when the main character drives a car through the countryside.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Indra Anagram

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 68
    • View Profile
Re: The illusion of vehicle movement across the scene (on the X-axis)
« Reply #2 on: November 25, 2017, 07:35:44 PM »

Hey Mnemonic!

The van is basically staying in the same place (moving a little to the left and right)

1. Do you mean something like this?



Basically you'd need just one script, that would move it's owner entity by decreasing its X position, and if X is lower than some threshold, it would increase it again and repeat the process.

2. I want the vehicle to move left, like in the example gif from my original post. Will the code resemble something like:

Code: WME Script
  1. if(X>1200)
  2. {
  3.   tree.SkipTo(X, Y);
  4. }

Or do I understand you correctly at all?

while everything else moves. For example, the trees would be "recyclable" entities, that move from right to left, and when they're off screen, they skip back all the way to the right and then move through the screen again. Same for the fog, houses etc.

3. I am creating a simple replica of the scene. How many layers should be in the scene? 3 or 4? I mean for background, emerging and disappearing house and back trees, the car itself (with floor region), and foreground with trees. Should those foreground tree entities be recycled one by one or as one long sprite?

THANK YOU for your kind reply and inspiration!
« Last Edit: November 25, 2017, 10:47:46 PM by Indra Anagram »
Logged
Owls are not what they seem...

Indra Anagram

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 68
    • View Profile
Re: The illusion of vehicle movement across the scene (on the X-axis)
« Reply #3 on: November 29, 2017, 04:59:47 PM »

For example, the trees would be "recyclable" entities, that move from right to left, and when they're off screen, they skip back all the way to the right and then move through the screen again. Same for the fog, houses etc.

Basically you'd need just one script, that would move it's owner entity by decreasing its X position, and if X is lower than some threshold, it would increase it again and repeat the process.

Dear Muties,

I've created a project called "Vehicle" and a scene called "Car" to achieve a rough replica of the scene from the original post here. All entities are loaded in the scene and the car entity has a simple animation of "movement" (smoke and mirrors, just like Mnemonic said  :)). Now I am stuck, because of several questions:

1. How should this scene be organized in terms of levels? In "Car" there are currently two layers: one for background2 (background image itself) and main for floor region and all entities. The idea is to mimic car movement by loading and moving trees and house in the background (behind the car) in the x-axis from left to right. I guess later the third level - for foreground trees - could be added, however the floor region can be only on the main layer. So, how do I organize the layers?

2. As you can see in the screen below, currently tree entities overlap the car entity, since all entities are loaded on the same layer. Is there a way to solve this and make the car entity overlap and cover everything that is "behind"?



3. I haven't found any info in the Documentation about scripting moving entities and the OldGuy entity in the demo project is pretty much static, so... How do I move tree and house entities in the x-axis? Looked through "Scene object" and "Entity object" sections in the Scripting reference, yet didn't come up with something like "GoTo" analog for entities. I am pretty bad at understanding scripts. Mnemonic replied me there should be basically one script. The problem is I seemingly understand the principle, yet cannot specify that with appropriate commands in the form of a working condition. My guess was something like this:

Code: WME Script
  1. while(treebg1.X>=1200)
  2. {
  3.  
  4. }

but I don't know if this will be right and again, what method, command or parameter should I use to move entities?

I disabled actor as Game.MainObject and erased Molly's lines from game.script. Should I make the car entity Game.MainObject now?

So many questions and I've tried different approaches for 2 - 3 days. Please help me with this scene, guys! After all, such things are pretty common for adventure games, and I think others might need it too. We could add it to the free resources section when it's ready.

Here are links to the source files. I've had some issues with Dropbox recently, so I made both zip and rar archives of same scene:

https://www.dropbox.com/s/1ykixggujdcd5xv/Vehicle.rar?dl=0
https://www.dropbox.com/s/5sjcz5isg5kj40m/Vehicle.zip?dl=0

THANK YOU for your kind attention and friendly advice!
Logged
Owls are not what they seem...

eborr

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 192
    • View Profile
Re: The illusion of vehicle movement across the scene (on the X-axis)
« Reply #4 on: December 02, 2017, 11:48:51 PM »

Not wishing to sound harsh but all you do is to reset the x,y coordinnates for each object within a loop. I dont have access to a win box at the moment but the code goes something like this


Myobejct.X =0;
while (Myobject.X <Screensize+objectsize)
  {
    Myobject.X = Myobejct.X +1;
    SLEEP(<some int >);
  }

Obviously this ie not pure WME script but I hope you get the general idea. You set this up as a script you can call, and invokr it for the duration. If you want to see this in action look at the cars in the background in the K'NOSSOS tutorial.
Logged

Indra Anagram

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 68
    • View Profile
Re: The illusion of vehicle movement across the scene (on the X-axis)
« Reply #5 on: December 03, 2017, 02:00:40 PM »

Hi eborr!

Not wishing to sound harsh but all you do is to reset the x,y coordinnates for each object within a loop.

You don't sound harsh, not at all - maybe a bit sophisticated  :), but that's the question of your experience in scripting compared to mine.

I added this piece of code to scene_init.script:

Code: WME Script
  1. treebg1.X=0;
  2. while (treebg1.X<800+512)
  3.   {
  4.     treebg1.X = treebg1.X+1;
  5.     Sleep(1000);
  6.   }

However nothing really changed - the treebg1 entity isn't moving anywhere.

Guess the problem is I misunderstand following things:

1. Should background trees be one big entity sprite or separate entities?
2. How exactly do I move the tree entities along the x-axis? What method or command should be used?

You set this up as a script you can call, and invokr it for the duration.

3. I am sorry, could you please provide more details?

If you want to see this in action look at the cars in the background in the K'NOSSOS tutorial.

4. Where could I read or download the tutorial to see the cars in the background?

THANK YOU, eborr!
« Last Edit: December 03, 2017, 02:02:24 PM by Indra Anagram »
Logged
Owls are not what they seem...

eborr

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 192
    • View Profile
Re: The illusion of vehicle movement across the scene (on the X-axis)
« Reply #6 on: December 03, 2017, 02:41:01 PM »

you need to set the sleep to between 5 and 10 otherwise it will take ages to cross the screen

to get the KNOSSOS demo

www.svarunentertainment.com

also on itchio and gog - but I don't have the links
Logged

Indra Anagram

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 68
    • View Profile
Re: The illusion of vehicle movement across the scene (on the X-axis)
« Reply #7 on: December 03, 2017, 04:31:05 PM »

you need to set the sleep to between 5 and 10 otherwise it will take ages to cross the screen

Hey eborr, you did this! The tree runs across the scene behind the car sprite  ;D

However, I had to disable car entity animation (that imitated its movement) in this line

Code: WME Script
  1. car.PlayAnim("entities\car\sprites\move.sprite"); //Set the car in motion

because otherwise your code wouldn't cause the tree entity move.

1. Is that possible to keep both the car entity animation and your script running?
2. Also the tree entity only moved to the right once. How do we cause it return to the initial position and repeat its path across the scene? How do we stop this behavior at a given moment?

to get the KNOSSOS demo

www.svarunentertainment.com

I will download and try the demo, eborr.

THANK YOU for your kind attention and help!
Logged
Owls are not what they seem...

Indra Anagram

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 68
    • View Profile
Re: The illusion of vehicle movement across the scene (on the X-axis)
« Reply #8 on: December 03, 2017, 05:05:11 PM »

you need to set the sleep to between 5 and 10 otherwise it will take ages to cross the screen

eborr, I am sorry for asking you about the car entity animation. Have just solved this by setting move.sprite in car.entity by default  :) .

Anyway I don't know how it is possible to make the tree entity appear at its initial position over and over again once your script has run (like in this screen)



and how to make this stop at a given moment. Should the script be modified? Or is it another script?

THANK YOU, eborr!
Logged
Owls are not what they seem...

Indra Anagram

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 68
    • View Profile
Re: The illusion of vehicle movement across the scene (on the X-axis)
« Reply #9 on: December 08, 2017, 12:59:35 PM »

Dear Muties! Still need your help with the scene. eborr's code works fine, yet I tried to set it to repeat numerous times and... nothing.

How is it possible to make an entity (such as treebg1) move across the scene over and over again?

THANK YOU for your attention and help!
Logged
Owls are not what they seem...

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: The illusion of vehicle movement across the scene (on the X-axis)
« Reply #10 on: December 08, 2017, 03:24:30 PM »

You have a loop (while) which moves the tree a little every few milliseconds. At some point, the tree moves way over the limits of the screen. If you leave it, it will continue to move indefinitely.

What you need to do is have an if() statement inside the while loop, which will check whether the tree has moved too much, and reset its X position to 0.
Logged

Indra Anagram

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 68
    • View Profile
Re: The illusion of vehicle movement across the scene (on the X-axis)
« Reply #11 on: December 09, 2017, 12:34:33 AM »

Hi anarchist,

Please kindly view these questions:

What you need to do is have an if() statement inside the while loop, which will check whether the tree has moved too much, and reset its X position to 0.

1. Does this script express your point?

Code: WME Script
  1. treebg1.X=0;
  2. while (treebg1.X<800+512)
  3.   {
  4.     treebg1.X = treebg1.X+1;
  5.     Sleep(2);
  6.         if(treebg1.X == 1200)
  7.         {
  8.           treebg1.X=0;
  9.         }
  10.   }

I tried it and it worked! The tree entity (treebg1) started racing across the screen repeatedly. However I have some doubts, if it is okey from your point of view.

2. I tried to think how this script could be applied to other tree entities and a house entity. Will the following approach be correct?

Code: WME Script
  1. treebg1.X=0;
  2. treebg2.X=100;
  3. while (treebg1.X<800+512 + treebg2.X<800+336)
  4.   {
  5.   treebg1.X = treebg1.X+1;
  6.   Sleep(2);
  7.         if(treebg1.X == 1200)
  8.         {
  9.           treebg1.X=0;
  10.         }
  11.  
  12.   treebg2.X = treebg2.X+1;
  13.     Sleep(0);
  14.         if(treebg2.X == 2000)
  15.         {
  16.           treebg2.X=100;
  17.         }
  18.   }

3. The code from the previous question seems to work, yet entity sprites behave oddly - they sometimes appear from the left edge of screen as if right from the air, from nowhere (not from behind the left edge). And sometimes first tree joins second tree on the run like the engine doesn't manage to "draw" it in time :D Well, of course, WME is not the reason, and I blame my imperfect math knowledge. Is there a way to improve this scenario somehow to make the entities  emerge more naturally?

4. In terms of question 3 I thought maybe if there was a way to only display a central area of the scene background, then the tree entities had enough time and space to appear at their initial positions while we don't see them, move across the visible scene area and then reach the limit positions in the second area that we don't see. Does that make sense? If yes, how do we display the central part of 2400 X 600 background? What can I make in SceneEdit or in scene_init.script?

Hope this screen will illustrate what I mean: 



THANK YOU, anarchist! The scene starts getting closer and closer to what it was thought to be, yet there are some things I can't resolve without help from the community.
Logged
Owls are not what they seem...

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: The illusion of vehicle movement across the scene (on the X-axis)
« Reply #12 on: December 16, 2017, 10:43:07 PM »

Code: WME Script
  1. if(treebg2.X == 2000)
  2. {
  3.    treebg2.X=100;
  4. }
  5.  

This approach is not correct. What you want is the entities to start on the start position, move right and then, when they have reached a predefined position on the right they appear on the left. Something like this:

Code: WME Script
  1. if(treebg2.X == 1200)
  2. {
  3.    treebg2.X=0;
  4. }
  5.  

This is also problematic:

Code: WME Script
  1. while (treebg1.X<800+512 + treebg2.X<800+336)
  2.  

First of all, the + sign here 512 + treebg2.X is incorrect. You probably meant to use the "and" symbol, which for Wintermute and a lot of programming languages is this &&. I would also rethink what to use in the while() statement. You probably want this script to run for a specific duration of time, so you could probably use a counter variable. There is also no need to use a lot of Sleep() commands in the loop, just once in the end, after you have moved all the entities.
Logged

Indra Anagram

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 68
    • View Profile
Re: The illusion of vehicle movement across the scene (on the X-axis)
« Reply #13 on: December 18, 2017, 08:36:44 PM »

Hi anarchist!

This approach is not correct. What you want is the entities to start on the start position, move right and then, when they have reached a predefined position on the right they appear on the left.

Do you mean ALL tree entities in the scene must have X=0 as their starting point? In that case how do we prevent them from overlapping each other (set a space/time delay between them)?

I would also rethink what to use in the while() statement. You probably want this script to run for a specific duration of time, so you could probably use a counter variable.

The reason for me placing the x-axis coordinates in the while() statement is that I misunderstand how this script could work for multiple tree entities, not just one. Or should there be a separate loop for each entity?

4. In terms of question 3 I thought maybe if there was a way to only display a central area of the scene background, then the tree entities had enough time and space to appear at their initial positions while we don't see them, move across the visible scene area and then reach the limit positions in the second area that we don't see. Does that make sense? If yes, how do we display the central part of 2400 X 600 background? What can I make in SceneEdit or in scene_init.script?

Hope this screen will illustrate what I mean: 



I still don't know the way to only display a central part of the long background image so that the starting and end destinations of tree entities were invisible. Any advice?

THANK YOU for your attention, time and friendly help!
Logged
Owls are not what they seem...

Indra Anagram

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 68
    • View Profile
Re: The illusion of vehicle movement across the scene (on the X-axis)
« Reply #14 on: December 22, 2017, 09:41:35 PM »

Hey Muties!

Finding the answers to these questions is a good way to overcome the background width limitation for everyone who would like to create a scene with "movement illusion". Let's come up with a template.

Please kindly view my questions about the script and scene setting in previous messages here. Any ideas on how the script could be customized for smooth "movement" of multiple entities?

This may seem as something obvious for a person proficient in scripting, but, honestly, to me this is not that easy.

Thank you for your attention, patience and advice, guys! 
Logged
Owls are not what they seem...

Indra Anagram

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 68
    • View Profile
Re: The illusion of vehicle movement across the scene (on the X-axis)
« Reply #15 on: January 13, 2018, 03:16:52 PM »

Basically you'd need just one script, that would move it's owner entity by decreasing its X position, and if X is lower than some threshold, it would increase it again and repeat the process.

What you want is the entities to start on the start position, move right and then, when they have reached a predefined position on the right they appear on the left.

Not wishing to sound harsh but all you do is to reset the x,y coordinnates for each object within a loop.

Hey guys!

Sorry, but I still don't understand how to make your script work for multiple tree entities. I tried to adjust it for several trees, and in the end it always causes errors and undesirable behavior. Please, if you know how the script should work, tell me what's the solution for several entities.

This script could be good for clouds too, btw.

THANK YOU for your friendly attitude and help!
Logged
Owls are not what they seem...

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: The illusion of vehicle movement across the scene (on the X-axis)
« Reply #16 on: January 13, 2018, 05:43:12 PM »

Lets take one of the scripts you showed as example and modify it. I will add comments in the code, please read carefully and understand what we are doing, DO NOT simply copy paste the code.

Code: WME Script
  1. //These are the STARTING POSITIONS of your entities
  2. treebg1.X = 0;
  3. treebg2.X = 100;
  4.  
  5. var amountOfLoops = 5000;
  6. var loopsSoFar = 0;
  7. //This is the maximum X coordinate for ALL your entities.
  8. //More specifically, this is the "edge" of your screen on the right.
  9. //Whenever an entity reaches this X coordinate, you move it to the
  10. //FAR LEFT (meaning X = 0).
  11. var maximumX = 1200;
  12.  
  13. //We will perform 5000 loops.
  14. while(loopsSoFar < amountOfLoops)
  15. {
  16.         treebg1.X = treebg1.X + 1;
  17.         if(treebg1.X == maximumX)
  18.         {
  19.                 treebg1.X = 0; //Move this tree to the far left.
  20.         }
  21.        
  22.         treebg2.X = treebg2.X + 1;
  23.         if(treebg2.X == maximumX)
  24.         {
  25.                 treebg2.X = 0; //See here? We move the tree to the FAR LEFT (X = 0), NOT to its starting coordinate!
  26.         }
  27.        
  28.         //etc. etc.
  29.         //You can repeat the same for all entities.
  30.         //There could be a smarter way to do this using arrays but for now try the simple version
  31.         //until you become better in programming.
  32.        
  33.         //We sleep for 10 ms and we will loop 5000 times.
  34.         //This means this whole animation will take 5000 X 10 ms, meaning 50000ms.
  35.         //You can adjust the amount of loops depending on how long you want the animation to take.
  36.         //If you adjust how long the Sleep() command takes, you will in result adjust how fast the entities move.
  37.         Sleep(10);
  38.         //Increment (add one) loops counter so that the loop ends at some point. There are other ways to do it
  39.         //i.e. catch the ESCAPE key press and change a global variable, but for now try the simple way.
  40.         loopsSoFar = loopsSoFar + 1;
  41. }
  42.  

I have not tested this code so if it produces errors let us know which errors appear, or better yet try to solve them yourself first  ;)

What I believe you were missing is that each entity, after it reaches the far right of the screen, it should move to the far left, NOT its starting position. This will work, because, even though the "max x" of each entity is the same and the far left position is always 0, each entity starts on a different X, therefore it will take each entity a different amount of time to reach the far right X coordinate.
Logged

Indra Anagram

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 68
    • View Profile
Re: The illusion of vehicle movement across the scene (on the X-axis)
« Reply #17 on: January 15, 2018, 03:18:21 AM »

Hi anarchist!

I have not tested this code so if it produces errors let us know which errors appear

Well, I did paste your code in scene_init.script after reading your helpful comments and guess what? No errors were identified in the debug. FANTASTIC!  ::thumbup

However, I keep getting this behavior from first tree entity (
Quote
treebg1.X = 0;
, remember?):

https://ibb.co/gvUr96

You see? First treebg2 entity appears in the FAR LEFT (no problem with that) and nearly a second later treebg1 emerges from nowhere.

, or better yet try to solve them yourself first  ;)

In the attempt to solve this issue on my own I changed the starting x coordinate of the car entity, however the result turned out to look even more unnatural: first we see both tree entities frozen in the FAR LEFT edge and the car entity drives in to its SkipTo point from the FAR RIGHT edge and finally trees start moving like they should  :(

My question is -
Is there a way to start the scene with this FAR LEFT edge hidden somehow from our view? Is it possible to shift the "view" a bit to the right in order to conceal the starting points of the trees? Please tell me what you think about this!

This way no one will notice treebg1 teleportation))

Here are the scene files for your kind consideration. This way we both will see what the issue is with those tree entities.

My background image is 2400 X 600 and the scene "view" is 800 X 600. Any ideas about shifting the "view" from the default FAR LEFT background edge to the right?

anarchist, THANK YOU for your patience and knowledge! I guess it is difficult to understand things that I try to express sometimes (like with this last "view" question). Maybe we perceive the problem from different angles - logical (you) and visual (me). Will really have to reinvent my mind to acquire a programming mind type lol.
« Last Edit: January 15, 2018, 03:44:57 AM by Indra Anagram »
Logged
Owls are not what they seem...
Pages: 1 2 [All]
 

Page created in 0.35 seconds with 17 queries.