Help with Falling and Collision

Hi @Spid3rtech,

Honestly, my first and foremost suggestion is that you build this outside of Composer, as one simple “main.lua” file. Composer is really a 2nd-level type of thing, and you shouldn’t just dive into that without understanding the foundation of what you want to add to Composer. Only when you have the basics in place should you attempt to place it into the scene management system.

Brent

Actually I do have the basics in place. My main.lua is already filled with my “Beginning” scene and then it “scene:goTo(mynextscene)” and it all works. so bassically, all I need to focus on is this. Think you can help me out by creating a new code? You said it takes like 2 lines of code… for me it took around 10, for just one thing… So if you actually do have time, can you please help me out? If you don’t have time to explain why you did what, I am good at figuring out what you did and how they work and all. I just really want to get this over with xD

OK, well at the very basic level, just transition the “spear” to the center of the screen, or rather the center of the “field” object:

[lua]

transition.to( Spears[SpearsCounter], { x=field.x, y=field.y, time=2000, onComplete=spinImage } )

[/lua]

But then, because the starting point will not be the same distance away for every spear, to accomplish a consistent rate of movement, you’ll need to adjust the time parameter based on the distance. See this post for an example:

https://forums.coronalabs.com/topic/39774-transitionto-with-constant-speed/

Hope this helps you get started,

Brent

Wait, so we aren’t starting over? Or am I adding to the code I have?

Well, you’ve placed some functions and objects in the wrong place(s) within the Composer template, but that can easily be fixed.

On this point, I again urge you to fully understand Composer before you get too much further along, as you will just encounter more problems if you don’t understand exactly how Composer scenes work and what elements should be placed where.

Today we just published a roundup on Composer tutorials and resources. Perhaps these will help you:

https://coronalabs.com/blog/2015/08/11/tutorial-treasury-composer/

Brent, like I said. I like learning from an actual person and actual code. I learn from that better. Links do help, but they do not have the full potential to help me with what I am looking for. For example, If you just made what we are talking about on here, I would probably learn more by just looking at all of the code you inputted then I could ever learn from the link you gave me. Even if you think that could help me, I have wasted a lot of time on links people gave me which did not do anything to help. So I would rather not try and waste my time on that… Sorry. But this post was created because of links.

Hi @Spid3rtech. I had to answer this same question in another thread today.  If you ask a question, then someone, be it Brent, me or a community member has to write an answer and potentially type in some code.

If you ask, then someone else asks a few days later, and some else asks a few days later, we end up answering the same question many times. This is why we write tutorials and ask people to search the forums to see if your question has already been answered. This is why we provide sample apps with the product and to be able to download from github. This is why almost every API has sample code in it’s documentation.  We do this so we don’t have to repeat ourselves over and over.

You tell us you don’t learn as well from links, but if you can read this forum post and read code here, there is no reason you can’t read it in one our tutorials or documentation pages since we would type the exact same answer here.

Please respect our time and the time of our Community members and try better to make use of links provided.  We are giving you the same answer there.

Rob

Well, the point of this post, is because I am looking for something specific. Not a tutorial on how to do Composer, I am pretty sure I get that. What I don’t get is how to do this specific thing.

Hi @Spid3rtech,

I gave you the starting code about 6 posts back, and in addition, a link to another post which contains the code you need for “constant speed”. I could copy the exact same code from that post into here, but you need to go copy it from there and adapt it to your project.

Brent

Actually I’m figuring it out right now. But if I need help I will ask! Thanks for the help so far.

Hi @Spid3rtech,

Before we can help you, we need more detail. Do you want the objects to actually be “pulled in” toward the center, like the center is a “magnet” pulling them toward it?

You mention that they “fall from random points”. Does that mean they fall under normal downward gravity, but then if they hit a region near the center of the screen, the scene changes?

Brent

Well, ok. Sorry about that. But this is what I mean. I wanted it so for example, an “Arrow”, yes, getting pulled toward the center of the screen. By spawning at random points I mean that they spawn outside of the screen, in all kinds of directions. So not that they fall only from the top, but from the sides too, and bottom, and not ONLY from those points, just randomly, like the top right, bottom, bottom left, etc. So yeah, think of earth, and a meteor that is coming towards it, falling to the surface, but now think of “Arrows” but that fall randomly around “Earth” to the center. Keep in mind that, that is an example. So when they touch the center object on the screen, it will lead them to the new scene. So Boom, an “Arrow” hit the center, the entire screen clears and goes to the next scene, where the same exact thing happens, but the center object changed.

Sorry for the long post. :confused:

OK, that clarifies it more. Does this “pull toward center” concept need to be the object moving directly in a straight line toward the center? Or would they behave more like satellites which should be pulled toward the center but not necessarily in a direct line?

Yeah, direct line. Also, If the (Example again…)“Tip” of the “Arrow” “Falls” forward toward the ground.(So much quotations xD) I can’t seem to figure that out too… 

How about the rate of “falling”? Is it consistent, or do the arrows need to speed up as if under the force of radial gravity?

Well I want them to fall at a certain speed, but maybe in the next scene they get a little faster, and the rate of spawning is not to much as well.

OK, but consistent speed or gravitational acceleration? If a meteor falls toward earth, it accelerates as it gets nearer because of gravity. If you want that simulation, then the approach is completely different than if you don’t want that behavior.

Brent

Ah, that’s what you were asking. I am thinking of consistent speed. So it falls at a certain speed the whole time, right? Then that’s what I need.

OK, got it. So in that case – and assuming there is no other gravity in the world – then I suggest you use simple transitions from the point the arrows start to the center of the screen. Then use a sensor object (probably a circle) that detect collisions. Is that about what you need?

Yup, that’s basically it. To me it seemed pretty easy. But it’s tougher than I thought it was. I have already tried inputting Radial Gravity and all, but something is wrong with my code, so I just decided to restart. That’s when I posted this.

By saying my code didn’t work, I meant that Radial Gravity worked, but when the object spawn I got an error. But since I have restarted I can’t show you it…