Spawn random sizes of Platform but keep same gap
Simple Gamer Arts
Member, PRO Posts: 305
So, I'm making a runner and I want to spawn different sizes of platforms, yet keep the same amount of distance from each other (platforms).
What formula could be used for this? I remember reading something about when self.position is = to Self.Size multiplied by 2 etc ect... something along these lines...
Any help would greatly be appreciated.
Comments
Platform position x you are spawning = previous platform x + previous platform width /2 + platform you are spawning width /2 + gap size you want
✮ FREE templates at GSinvention ✮
✮ Available for hire! support@gsinvention.com ✮
@-Timo- Hi and thank you! I've been trying to decipher your formula on the actual game but haven't had any luck.
This is what I'm doing so far...
Could you work with me on that step by step, like:
Make actor 1
in Actor 1 do this and that
Make actor 2 and do this and that.
Very tough to achieve this... I tried tutorials and everything yesterday and today and still can't even see the light at the end of the tunnel for this sort of formula.
It's another million dollar question...
... the thing is, the future spawned platform's SIZE is random... so there is no way of knowing it's size in order for it be used in a formula.
I can only thing that the spawning of the new platform has to be done quite far off screen and then there must be a change attribute that moves the new spawned platform to a certain distance from the previous platform (which should be ahead already)
Is this the effect you're looking for?
If so, this was accomplished by using a separate spawning actor slightly off screen that spawned multiple overlapping platforms at a consistent interval associated with the game attribute 'gap'. Hopefully it helps.
WOW! this is exactly what I want, thank you! @Cutscene Entertainment
VERY MUCH APPRECIATE IT!!!
I can create a little demo for you if you want. Seems like @Cutscene Entertainment already made what you are looking for though?
Your code Is in the right direction, everything is just a bit off.
You are spawning a new platform before you changed the width to a random size or the attributes are changed. Move the rule under the change attribute.
Constrainging an attribute means constantly changing an attribute to a value. When you have multiple actors all constraining a game attribute to their x position it's not going to work.
In this case you would only need the value once so a change attribute would be fine here.
You are spawning the new actor om position x2000 y0 relative to scene. So the position of the new platform will always be x2000 y2000. The x position of the new platform should be the formula I gave you. (Wont work to put this in the spawn actor behavior because like you mentioned you don't know the random width yet)
Changing the things I mentioned won't fix your problem but are really important to understand. I could give you a step by step tutorial on how to do it but the best way to learn is to make mistakes, understand why it's a mistake and then fix it yourself.
There are many ways to get what you want. Read through the code from @Cutscene Entertainment demo and try to understand it but don't just use his code for your project. Try to fix your own code.
If you are still having difficulties, with the working demo and some of my "tips" just let me know and I will explain step by step why your code isn't working and what to do to fix your code.
✮ FREE templates at GSinvention ✮
✮ Available for hire! support@gsinvention.com ✮
Ah, Thanks. Glad I could help.
@-Timo- First of all thank you for the explanation, but I think I will need your help; this level of code, it's just beyond me and I have come to a complete halt in my game because of this. I mean, I want to learn, yes, I've tried/failed for a couple of days on this non-stop but don't know what else to do... I could hire you for a session on Skype. I see your email for hire is: support@gsinvention
(the demo CUTSCENE sent was useful and I adapted it and achieved what it was meant to do... but there is one further step that I was not able to achieve that the demo does not offer... which is alternating Platform's Y position... one spawns at the bottom, then the other spawns at the top and so one and so on... this I could not achieve with that demo's method... I had achieved it with another method, but couldn't apply it to CUTSCENE's demo's method... So, basically, I now have achieved both game structures but have not been able to combine them into one...)
VICTORY, I did it. I resolved it! Thanks for the help everyone! I was able to modify the DEMO Cutscene Entertainment sent me to fit my needs.
@-Timo- @Cutscene Entertainment
Awesome! glad to hear. Hopefully, you understand what you did and why it wasn't working before.
✮ FREE templates at GSinvention ✮
✮ Available for hire! support@gsinvention.com ✮
@-Timo- Yes, I analyzed the hell out of it and and understood most of I believe. Thanks. Was able to manipulate it to my liking and even add to it.