Scrolling background problem
Hi. I'm making a side scroller shoot em up. At the end of the level, I want a doorway to scroll into the scene and I want the player to have to shoot the door to proceed to the next level. I have the doorway setup as its own actor and scrolling at the same rate as the background. So once the background completes scrolling, the doorway is present in the scene. I'm having a difficult time getting the doorway to not move if the player touches it. I can't turn the movement off in the physics of the door, since it's scrolling at the same rate the background is. I have the bounciness set to zero. Even though I have a Collide behavior attached to the door, and the player can't go THROUGH the door, the player can still push the door around. Which I don't want. I want the door to scroll into the scene along with the background, and the player to not be able to push the door around, or go through the door until it's destroyed. How can I do this?
Comments
You could maybe constrain the door actors position to a specific x,y coordinate on the background actor? There's a gshelper tutorial on constraining one actors position to a specific point on another.
Nope. That's not working.
Have you tried constraining it to the background but turning movable off?
No. I'm trying to do that now, but when I add the constrain attribute, the background isn't an option. I've got it set up like this:
Constrain: self.position.x to:
and in the 'to' pop up window, I select Attributes - then there's Game, Devices, Services, and Doorway (which is what the door actor is named). There's no option for Background 1 (which is the actor I want to constrain the door to). ??
you need to add 2 real attributes within the door actor called "hold X" and "hold Y" then make a rule when the doors self position is where you want it on screen Change self.hold X to self.position X and self.hold Y to self.position Y
then below those rules
constrain to self.linear velocity.X to 40(self.hold X-self.position X)
constrain to self.linear velocity.Y to 40(self.hold Y-self.position Y)
then turn on fixed rotation
Hope that helps
Well, that doesn't seem to be doing the trick, either. I think I'll have to list most of my coding (or behaviors, or whatever the technical term is):
I've got actor Background 1 (which is the background) set to Motion: Linear Velocity: X: -6, Y: 0 (which is giving me my scrolling effect). And then for behaviors, I have a Rule set up with Attribute: When all of the following are happening: if self.position.x <= -233 (the X coordinate I want the background to stop scrolling).
I've got three actors with the word door in it: Door, Doorway, and Door Breaks (the third of which is simply an animation for when the player destroys the Door). Both the Door and Doorway are set to Motion: Linear Velocity: X: -6, Y: 0 so they match the background's scrolling. Both the Door and Doorway have a Movement Rule with Attributes: if self.position.x <= (and then their corresponding X coordinates where I want them to stop - for the Door it's 377 and the Doorway it's 423), and a Change Velocity within the rule with change movement to go in direction: 0 relative to actor at a speed of 0 to make them both stop scrolling at their designated X coordinates. Both the Door and Doorway actors' physics have a Density of 1, Friction of 3, Bounciness of 0, and Moveable is checked on.
My goal is to have the Door and Doorway scroll into the scene along with Background 1, have all three (Door, Doorway, and Background 1) stop at a given X coordinate, and have the player shoot the Door until it's health is 0, then trigger the Door Breaks actor to animate the door shattering. Then trigger an automated "level 1 clear" scenario where the player will automatically pass behind the Doorway and have the scene fade out. I also want to make sure that the player cannot push the Door or Doorway actors around. I've added two Collide behaviors to the player (for both Door and Doorway), and one Collide behavior to the Door (for the player's projectile weapon; an actor named Energy Blast).
So far the Background 1, Door, and Doorway actors scroll and stop perfectly. The Energy Blast actor triggers the Door's health and when the Door's health reaches 0 the Door Breaks animation triggers perfectly. So I also have a Door Damage rule and Door Destruction rule added to the Door as well.
@ashtmj - I did also try your technique mentioned above. I started with the Door actor and worked all of your steps out on that as best as I could figure, and when that didn't work, I decided to respond here, rather than add my interpretation of your code onto the Doorway actor as well. Here's how I have interpreted your suggestions:
On the Door actor I added two Real Attributes. I named one Hold X and the other Hold Y. both of them are set to 0. I added a Rule that states: When all of the following are happening, if self.position.x = 377 (where I want that particular actor to stop scrolling), then I added two Change Attributes: set self.Hold X to self.position.x and set self.Hold Y to self.position.y. I also added two Constrain Attributes: constrain: self.motion.linearVelocity.X to 40self.Hold X self.position.x and constrain: self.motion.linearVelocity.Y to 40self.Hold Y self.position.y. Now the Door won't even scroll into the scene with that Rule turned ON.
And just in case, I'll list the beginning coordinates: Background 1: X: 713, Y: 160; Door: X: 1323, Y: 158; and Doorway: X: 1369, Y: 160.
What am I missing here?
oops! I missed one bit! should have had * in the code
like so:
constrain to self.linear velocity.X to 40 * (self.hold X-self.position X)
constrain to self.linear velocity.Y to 40 * (self.hold Y-self.position Y)
Anyway
I've attached a project for you with this working
-Ash
Well, that didn't work either. The Door and Doorway came flying right at my player. lol It was pretty funny, but not what I'm going for. lol. For some reason the Door and Doorway were on some sort of scroll on steroids. And they scrolled as soon as the scene loaded. No wait time.
Aaaaaaand I can't open your file because it claims that your file was made with a newer version of Gamesalad. Could that be because I'm using a free version and you have a Pro version..?
I'll give it a go in a couple hours when I get home, if I figure it out I'll post the file. I currently have free as well so there shouldn't be a version problem if that is the reason you couldn't open his file
Anyone..?
@ashtmj well, I figured out that I can open your file after all. I just can't open it if I have a different file open for some reason. I have to close Gamesalad and double click on your file and open it that way. Weird. Anyways, after much toil, I finally got the door to properly collide with the player character without the door moving AFTER it's done scrolling. I couldn't figure it out for most of today - I had my code EXACTLY how yours was, but the door would still move off screen if the player touched it. I then noticed that my door actor's density was much lower than your scrolling wall actor. I cranked the density of my door up to 5,000 and it finally worked the way I wanted. Now, there's still one more slight problem here. If the player touches the door actor AS it's scrolling into place, it will move. It's only AFTER the door is finished with its scrolling protocol that the player can't move the door. Is there a way to prevent the door from sliding off screen AS it's scrolling if the player touches it?
I've been reading all these post about endless scrolling backgrounds and I don't understand what all the hoopla is about. I just set my scene to wrap y (or wrap x if the game is landscape), place your background image and stretch it beyond the viewing edges of the playfield and set the move to whatever direction you want. That's it. Works fine on my game.