Movable platforms
I'm trying to make a platformer type game, with moving platforms. I've searched some tutorials online, but haven't found any that talk about moving platforms (they all make you uncheck "movable"). I've tried messing around with it myself, but haven't had much success. Does anyone have any idea how to do this?
Comments
So for example, to move a platform left or right you could do something like this
First create an instance MoveState attribute for the platform (Inside the actor, if you don't know how to do this double click the platform actor, then on the left hand side in the middle you will see a "+" and "-". click the "+" to make a new attribute just for this actor.
Then choose integer.
Name the Attribute MoveState
Inside the actor make the following rules
Timer - Every 1 Second
Change Attribute - MoveState -> (MoveState+1)%2
(this changes the the state back and forth between 0 and 1 every 1 second)
Create Rule
When MoveState = 0
Interpolate - SelfPos.X -> SelfPos.X + 100
Duration 1 second
Create Rule
When MoveState = 1
Interpolate - SelfPos.X -> SelfPos.X - 100
Duration 1 second
That should get simple platforms moving left and right. However you should know that using too many timers can slow down your game.
You can mess around with the numbers to change the speed or how far they move.
turn movable off
turn fixed rotation on (to stop it rotating).
When the player is on the platform you'll need to constrain the movement of the player to the moving platform.
Get the platforms to work right first, then see what happens.
I tried turning off movable--no go. I'd love to see your template, icanmake.
micksolo, how do I constrain the movement of the player to the moving platform? I'm not sure how I'd do that. Would I make attributes for the box, or the player?
You're going to need to learn about instancing and setting unique ID's for each platform. Unless of course you have each platform as it's own individual actor, but that system is annoying because if you make 1 change to a rule in the platform you have to make over and over again in each actor.
Better to learn how to constrain first, then learn how to set each platform as its own unique ID.
I'd suggest doing something like this:
Create a global attribute integer : Platform ID
Create an instance attribute in the platform actor called SelfID
Create a global attribute boolean called "OnPlatform" (set to false by default)
In the Player actor:
When collide with actor Platform
Change PlatformID to PlatformID +1
Change OnPlatform to True (otherwise OnPlatform = false)
In the Actor Platform
When OnPlatform = True
Constrain SelfID to PlatformID (this sets an individual ID for each instance of the platform)
Create a rule
When SelfID = Platform ID
Constrain PlatformX to SelfPosX
Constrain PlatformY to SelfPosY
(this makes it so that whatever platform the player is on, the global attributes PlatformX and PlatformY will set to the current platform. If you don't do this basically whenever the player touches a platform the code won't know where to constrain the player too as there are more than instance of the same actor, and it will probably crash.
Hope this helps, if you need any more help or have trouble implementing it feel free to send the project file my way. But you should try to implement this yourself first, its the best way to learn
Also, thank you micksolo--I'm using the stuff you said to have the player only stand on the platform when it's on top of the platform, and not hitting it on the side.