Player Sticks to Layout Bounds

0 favourites
  • 10 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • If I move my player to to top of the layout and continue flying upward, it takes a while for him to start falling. If I fly to the left or right edge and continue for a few seconds it takes the same amount of time flying in the reverse direction before he moves off the wall. The same goes for the floor. Initially he launches just fine. But if I let him settle for a few seconds it takes the same amount of time flying upward to get him to leave the ground. Is there a way to prevent this?

    https://www.dropbox.com/s/1yhhqviwap3qk7j/Test.capx?dl=0

    Thanks

  • This seems to be a simple question that I can't seem to find an answer for.

  • The problem is you have a max speed of 600, but only a acceleration of 125 and declaration of 75. If you now are going to the left and hit the left boarder with full speed and now you want to the right. The speed has to decrease from 600 to 0 and this takes its time, because of your acceleration before you can go to the right. The same is for right and the top. The bottom is a little different. You are using the Bullet-Behavior for gravity, but the gravity increase over the time, even if you sit on the bottom. So if you wait a little the gravity is over the max speed and you can not move anymore. You can see that if you go in Debug-Mode and look on the gravity of the Bullet-Behavior.

    You shouldn't mix so many moment behaviors. If you want use the physic-behavior you should use only the physic behavior, and the physic-behavior doesn't like the solid-behavior. So you have to be cautious what behaviors do you use.

  • I couldn't figure out how to get gravity working right with the Physics behavior so I deleted it after I added the bullet behavior. If I turn the acceleration up the player changes direction too fast. So how else can I go about getting a smooth direction change and gravity and not have these problems?

    Thanks.

  • You have to make borders that you can set the speed to 0 in this direction if you come to the end of the layout. In your case there are no sprites that can be used as borders. So you have to make virtuell borders. You have only to look if you on one end of the layout. I change your example a little bit to show what I mean.

    https://drive.google.com/uc?export=down ... C1XeElrR3c

    Please feel free to ask if it's not clear what I'm doing.

  • Thanks a lot. That helps. There are so many ways to do things in this program I never know what to do. It would be nice if someone made a tutorial on various movements and explained why to use one over the other. It's all fairly confusing to me.

    So help me understand this...

    For the viewport borders you are comparing the player's positions. "If X > ViewportRight(0)-PLAYER.Width/2-1" tells this event if the player gets within 1 pixel of touching the right side of the viewport to set the 8 direction vector X to 0 correct? I watched this in debug and it helped me understand it better. This is based off the player origin point right?

    ViewportRight(0) - I think I see what this is doing. So Viewport[direction](X) tells it to take the position from the viewport edge in the direction specified (X) pixels from that edge?

    Thanks again.

  • Thanks a lot. That helps. There are so many ways to do things in this program I never know what to do. It would be nice if someone made a tutorial on various movements and explained why to use one over the other. It's all fairly confusing to me.

    I can only recommend to read the manual. It's really worth to read, most of the questions are answered there.

    [quote:74c7vlvb]

    So help me understand this...

    For the viewport borders you are comparing the player's positions. "If X > ViewportRight(0)-PLAYER.Width/2-1" tells this event if the player gets within 1 pixel of touching the right side of the viewport to set the 8 direction vector X to 0 correct? I watched this in debug and it helped me understand it better. This is based off the player origin point right?

    This is exactly what it does. The player origin is a very crucial for this. If you have an animation where the origin is on different positions, you get a bug that is very hard to track down. If you use this kind of condition.

    [quote:74c7vlvb]

    ViewportRight(0) - I think I see what this is doing. So Viewport[direction](X) tells it to take the position from the viewport edge in the direction specified (X) pixels from that edge?

    Not exactly. The x is only the layer of the viewport. If you have different layers you can change with 'Parallax' in the Layer-Properties the scroll speed. So the viewport can be on different position on different layers. I could have used Vieport("BG") instead of Viewport(0), it's the same.

    The viewport itself is only a window of the layout what you see. You can scroll the viewport around in the bounding of the layout. The size of the viewport is the size of 'Window Size' in the 'Project-Settings'. In your example if you use the 'Test_Layout' the Layout and the viewport has the same size: 1920x1080. So in this case there is no scrolling. All Layer have the same viewport position. ViewportLeft(0) is X=0, ViewportRight(0) is X=1920, ViewportTop(0) is Y=0, ViewportBottom(0) is Y=1080. But the position of the Viewport depends of the scrolling in the layout, so the Viewport values are NOT always 0 and the window.height / width.

    Another crucial point is that the origin of the coordinates are top left. Maybe that will help to understand the vector X and Y a little bit better. I set the Vector X or Y to zero if you are on the border of the Viewport and you have the velocity to this border, otherwise you couldn't fly in the opposite direction. The velocity would always be 0 if you are near the boundary. So if you the gravity drag the object down you get a positive vector y, because of the coordinates.

    My example should also work if you scroll in a bigger layout, because with the 'ScrollTo-Behavior' the object is always in the center of the viewport. The exception is when you got to the boundary of the layout, then the object should move to boundary of the viewport.

    My english is not the best, I hope that makes all at least some sense to you.

    Please ask if something isn't understandable.

  • I have a very hard time absorbing anything I read in a book unless I am following an example in the software. I have the manual open 24/7 on my PC. But it is rare that I go to it and come away with an answer to whatever problem I am facing simply because the book doesn't have a section labeled "player movement is not correct". I have followed numerous tutorials. But every time I start to make a level of my own I get stuck right away. I understand some of the logic when I see it in examples. But creating it is my problem. I wish there were someone near me that could teach me hands on. That would help me more than anything.

    I understand the coordinates all come from top-left. That is why the ViewportRight(0) threw me, because far right would be 1920. So the "0" means nothing basically? I am still a little confused. ViewportRight is telling it the far right edge of the viewport then? I was unaware the viewport is on a layer. So that is confusing me I guess.

    Thanks

    Oh, your english is fine

  • I have a very hard time absorbing anything I read in a book unless I am following an example in the software.

    I have the same problem. I'm trying to make an little example or if it's possible to split the problem in tiny pieces and make for each a little example to look what happens. For this it's necessary to use the debugger or use a text-object and put the values in it. And there is always help in the forum here. <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    [quote:20rguqpk]

    I understand the coordinates all come from top-left. That is why the ViewportRight(0) threw me, because far right would be 1920. So the "0" means nothing basically? I am still a little confused. ViewportRight is telling it the far right edge of the viewport then? I was unaware the viewport is on a layer. So that is confusing me I guess.

    Don't confuse layout with the viewport. I made a litte example:

    https://drive.google.com/uc?export=down ... 2t4aU5jQW8

    In this example you have 8 Direction movement. You will see the coordinates of the object (green square) and the boundary of the viewport and Vector X and Y of the object.

    The layout has 1708x960 pixel the viewport (window-size) is 854x480. If you move the object you will see that the coordinates will change but if you subtract ViewportRight from ViewportLeft it will always have 854 pixel, the same with Bottom and Top this will always be 480 pixel. In this example I use the name of the Layer in the Viewport Viewport("L2"). As long the Parallax is not changed it is regardless of which layer you use or if you use the name or the number of the layer, so it is regardless if you use "L1" or "L2" or 0,1, in this example.

    Try it out and I hope it will do more help than confusion. <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • That is a great example. I can see what you are saying now. And looking at that example and comparing the code in the first example I think I get it now. Thank you for being patient and helpful.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)