So I was wondering if it’s possible to make moving platforms. I’m not sure how to go about it however.
One good starting point for moving platforms are kinematic rigid bodies. Those are bodies that don’t have mass and can be moved using regular entity methods while colliding with other bodies.
You can use a pc.Tween to move your platforms in a repeated manner.
Check at this manual page at the end on how to get started with kinematic bodies:
So I’ve figured out how to move the platform, however, how you I change the direction is moves. (So instead of moving it on X moving it on Y or Z since the game is 2D). And if so, would I need to make another script for vertical movement?
Hey @Overbaked, as @Leonidas mentioned, you can achieve this by tweening. This is the official tutorial for the PlayCanvas tween library. You can tween an entity on any axis, so it will work perfectly for you, both for vertical and horizontal movement.
Ok, so I read over the tweening information and when I try to tween something I get an error that reads “Cannot read property ‘getGuid’ of null”. I tried reading over the library’s Read Me but I’m not sure what’s causing this error. Sorry for the many questions.
Try sharing your code and if possible a sample project that reproduces your issue.
Sure, it is a bit messy though since I’m trying to get the base mechanics out of the way first. I also copied the script from the tween script to try and dissect it.
The project: PlayCanvas 3D HTML5 Game Engine
I tried running the project you linked, but I’m not able to reproduce the issue. Could you please post instructions on how to arrive at the error and/or create a smaller sample project that just shows the error?
Sorry, I edited the project while I waited for a response and removed the script so I could play test how it looked without it refusing to load. However, upon giving a platform a prebuild “tween position” script I now get a new error. The game loads, however it gives me “this.entity.tween is not a function”.
Here’s the project by the way: PlayCanvas 3D HTML5 Game Engine
This is because your copy of the tween library has been erased or corrupted for some reason:
Reimport the script and try again.
All right, I reimported the script and it works. However I have several questions.
Would I need to make a new script every time I want to apply moving properties to a platform? If so would I use the same script and just specify the Local Position.?
How would I get the collision of my platform to move with the platform? The model is moving but the collision stays the same.
Thank you sooo much for your assistance so far and sorry for so many questions.
You can write your script so that you can add it to multiple entities. (Like for example using
this.entity). If you don’t want all entities to do the same movement, you can create a script with multiple functions and assign each function to a specific entity. However, for beginners it would be easier to create different scripts.
Your collider will normally just move along if it is added to the same entity as your script. Currently, I think you mistakenly added your platforms to another platform as a child. With this setup, only the selected child with the script and the other components of this child will move. (The other entities doesn’t have the script and will not move).
By the way, I think if you create a parent entity with the script and add all your platforms as child to it, they will all move too. But then they will make the same movement, I don’t know if that is the intention.
Oh that wasn’t my issue though thanks because that’ll be useful for stuff later. However, I had to change the rigidbody to kinematic. I’ll make the bouncy platforms another thread, thank you sooo much!