Path To The end Of The Screen

ChessPawnChessPawn Member Posts: 127
edited November -1 in Working with GS (Mac)
Hi guys,

I really need your help with this problem. For those of you who are going to say "Try it yourself" or "ask your math teacher", that's already taken care of. I've been trying this problem for the past 2 months, and I figured everything out but this. So I am using ORBZ trajectory demo, and the gun is getting changed to a moving character that moves according to the trajectory path. I have fixed things such as angle and rotation to work anywhere on the screen using an offset. The only thing I can't figure out is getting the dots to spawn from the middle of the character to the edge of the screen, and yet still form a perfect curve. The dots either move up and down as a set, or just disappear. I know the problem falls where the actor "Gun" tries to spawn the dots using this formula "self.Plot Index / self.Plot Points * game.Display Size.Width", but I can't think of the math that will let the dots spawn from the middle of the "Gun", yet still retain all 30 dots and form a perfect curve.

NOTE:

Plot Index= 0 (changes by 1 every time one dot is spawned)
Plot Points= 30
Width= 480

If anybody can help me out with this, I will be really grateful.
«1

Comments

  • ChessPawnChessPawn Member Posts: 127
    BUMP (anyone?)
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    I may not understand completely what you are asking, and don't think I can help much with the math. But couldn't you place a image of a large circle on the scene. Move it down so that only the upper third is showing. (So you only see the upper ark of a ciricle.) You can then place your 30 actor instances along the ark. Once you get them placed exactly where you want them, you can look at the xy coordinates of each instance and note its position. Then, in your gun actor, you could spawn them with the exact xy coordinates that you want.

    This will also work even if you want them to be spawned with different starting locations (based upon gun location). You would need to do a little bit of addition and subtraction to get the offsets from the gun location.

    This may not be an elegant solution, but it beats trying to work out a parabolic function to describe a perfect curve.
  • ChessPawnChessPawn Member Posts: 127
    Interesting… I'll try that. I agree though, it may not be elegant, but it's easier than a parabola. However, that's still on my wish list for figuring out! :P (CookBook Video anybody?)
  • ChessPawnChessPawn Member Posts: 127
    EDIT: So I tried to the strategy said here, and it worked when the gun was at (0,0). However, it didn't work anywhere else… The dots started moving up and down. Does anybody have any ideas?
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    I don't quite catch what you mean by "the dots started moving up and down." Can you explain a little more of what is going on and the behaviors that you have on the dots?
  • ChessPawnChessPawn Member Posts: 127
    This demo is downloadable, if you wanna follow along.

    http://tinypic.com/r/2njeydz/7

    This should answer most questions… Or maybe not!
  • ChessPawnChessPawn Member Posts: 127
    BUMP...
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Hi ChessPawn,

    The video shows that the game is coming along nicely! The spawning works pretty well.

    It looks like the equations for the dots need a little tweaking. Basically the dots need to be offset a little so that they line up with the gun's new position. Here is what to do:

    1) Make a new game attribute. Name it GunX. (Make its type 'real'.)

    2) In the gun prototype -- add an new constrain behavior:
    Constrain Attribute: GunX To: self.Position.X
    Put it first thing, right at the top.

    3) In the mouse down rule of the "Plot Point" prototype -- modify the constrain attribute equation to the following:
    max(-10, self.Init Y +( self.Position.X - game.GunX )*tan( game.Launch Angle )-(game.Gravity*( self.Position.X - game.GunX )^2)/(2*( game.Launch Velocity *cos( game.Launch Angle ))^2))

    (Basically, its subtracting game.GunX from each point's xPosition. Notice that it's in there twice.)

    That should offset the dots for you!
  • ChessPawnChessPawn Member Posts: 127
    I don't understand what you mean. Aren't the dots already offset? It works except for when I move the gun off of 0,0. That's the only problem I have… The dots are staying moving up instead of curved.

    EDIT: Using the formula above, the dots don't move...
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    ChessPawn said:
    I don't understand what you mean. Aren't the dots already offset? It works except for when I move the gun off of 0,0. That's the only problem I have… The dots are staying moving up instead of curved.

    EDIT: Using the formula above, the dots don't move...

    It will work! I promise!

    The dots are offset when they spawn OK. But they are not offset correctly when you move them with the mouse. (That's in the part that we are changing.) In the video you showed that the dots were moving up with the mouse -- but they were not in the right place. That is why the projectile's path does not match the dots. The dots are not being offset to the correct path. The above modifications will fix that.

    When you modified the formula, and the dots don't move anymore -- that means the formula has an error in it. For example, did you put the extra parentheses in? Did you use the drop down menu to access the 'game.GunX' attribute (or did you type it in)?

    Remember, you are modifying the part that says 'self.Position.X' to now read:
    ( self.Position.X - game.GunX )
    including the parentheses. It is in there twice.

    Hope this helps.
    RThurman
  • ChessPawnChessPawn Member Posts: 127
    Holy. Sh*t. RThurman, you are the best person ever. What a math wizard. Holy crap. Dude, you don't know how excited I am!! GS, make this guy a Sous-Chef!! Now if you can answer this question, I am so putting you in the credits!! If I put the mouse on the right, the dots go the right. (Simple, right…) But if I put the mouse on the left, why do the dots not go to the left?
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    ChessPawn said:
    If I put the mouse on the right, the dots go the right. (Simple, right…) But if I put the mouse on the left, why do the dots not go to the left?

    Doh!!! I knew that question was coming next!
    See in the equation you modified where it says:
    max(-10, self.Init Y + self.Position.X *tan(.......................))

    That is a max function. It means choose the maximum number, either "10" or (whatever that big long equation evaluates to). Its basically saying 'don't let the number get smaller than 10'. Or another way of saying it is -- don't pay any attention if the mouse goes to the left.

    Hang in there!
    RThurman
  • ChessPawnChessPawn Member Posts: 127
    Another question: So I have the gun set up to move just like the projectile is, but the gun has to rotate so that it can move. Is there any way I can make the gun move like the blue projectile, but without it rotating?
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    What would happen if you make a rule that the gun's x position follows the mouse.position.X? That way, you could move the gun and set its rotation all with the mouse.
  • ChessPawnChessPawn Member Posts: 127
    I figured it out, I'm upping another video in a few minutes hopefully. I really need to know how to make the dots work all around…

    EDIT: Here's the video

    http://tinypic.com/r/2lca13n/7
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    ChessPawn said:
    Here's the video

    http://tinypic.com/r/2lca13n/7

    Hey! Its looking good!
  • ChessPawnChessPawn Member Posts: 127
    This is gonna drive me nuts!! I can't move backwards because the dots don't show up!! > : (
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    ChessPawn said:
    This is gonna drive me nuts!! I can't move backwards because the dots don't show up!! > : (

    I guess last evening's hint was not good enough. I needed to be somewhere else and didn't have much time to form a good explanation. Sorry about that. I will try again.

    OK -- so now its back to the original question. The one you started with!

    You now know that the trajectory is being plotted by the weird long equation in the "Plot Point" actor. You also know that the points can't go below -10. That's the -10 in the (max(-10, self.Init Y + self.Position.X *tan(.......................))

    But the points are all still there! They are just below the bottom of the screen. (That's the -10 part again.) How about making them so that that can't go lower then 50 pixels up the screen. How about this, change the equation so that instead of "-10" it says "+50". Then they should all show up. And you should start to get a trajectory showing up on the left side of the "gun".
  • ChessPawnChessPawn Member Posts: 127
    It doesn't work as expected. It just makes the dots form a line at y= 50, and they don't appear on the left side.

    http://i54.tinypic.com/xn85dj.png
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    I forgot -- you are probably spawning the dots by hand and offsetting them from the 'gun'.

    Can you go back to the original way that the demo spawned the dots? Starting from the left side of the screen and going across? (You can also increase the number of dots by changing the "plot points" attribute inside the gun actor. Change it so you have lots of dots. Like 120 or something.)
  • ChessPawnChessPawn Member Posts: 127
    It brings the dots over to the left (hurray)! But, as seen in the image, it still stops at y=50, making a weird line, and the dots don't start from the center of the gun. (BOOOOOO!)

    http://i54.tinypic.com/2enxr4g.png

    I put the GunX thing back in, I increased the dots to 120, and set the max to 50, (long equation).

    So close, yet so far away! :P
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    ChessPawn said:
    So close, yet so far away! :P

    Um.... that's pretty close! In fact, that's exactly spot on!

    The dots never did start from the center. They were just below the scene so you didn't see them laying flat like that. Do you see the ones that are on the gun? Those are the ones you thought were 'the start'. But they were never 'the start' (the others were always there -- just hidden).

    When you switch the equation back to -10 you will get a view much like you want. The dots will rise and fall in the ark you are looking for. (But you and I will know that the rest of the dots are hidden just below the bottom of the scene.)

    Maybe this will help.... The dots are set in place in the beginning. Then all you are doing is changing their Y position with the big long equation. But their X position never changes. See they go up and down with the same X position. Only the Y position changes.

    Hang in there!
    RThurman
  • ChessPawnChessPawn Member Posts: 127
    But I mean like when I set the spawn of the dots by hand, they started from the center of the ninja/gun. Now however, they start from the side again, but left and right work perfectly. How can I get the dots to start from the middle of my ninja/gun?

    http://i54.tinypic.com/2q2mozn.png

    Here is what I am trying to accomplish. Any questions I have are coming from this video:

    http://tinypic.com/r/2qav78k/7

    THANKS A LOT :P
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    OK -- maybe 120 dots was a bit too much. I just wanted make sure you to see the principle behind everything. I bet if you put 120 (or even 60) dots in your ninja system, you would probably see some of them below the ninja. Its just that there were so few on the screen that you didn't see them ark up from below. Maybe you want to go back to fewer dots? Try experimenting with the number of dots a little. Perhaps you can find a good compromise?

    You can also set the gun/ninja back down near the bottom of the scene. The that will hide most of them behind the gun. Would that help?

    Another thing to keep in mind is that the illusion of how the dots are generated might now be broken for you. But it won't be for your audience. Just because you know (and can now see) the secret does not mean that your users will. Its like being a magician -- to the audience it looks so real, but the magician knows its all just a simple illusion.

    Closer and closer!
    RThurman
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Here are a couple more things that might improve the user experience.

    1) Modify "Calculate Launch Angle as angle to mouse" This behavior is probably the second one in the gun prototype.
    Constrain Attribute: game.Launch.Angle To: vectorToAngle(( game.Mouse.Position.X -self.Position.X),( game.Mouse.Position.Y - self.Position.Y ))

    This will calculate trajectory movement from the center of the 'gun' rather than the left side of the scene. (You won't need to move the mouse so far to the left to make things work.)

    2) Modify "Calculate Launch Velocity as distance from mouse" This behavior is probably the third on in the gun prototype.
    Constrain Attribute: game.Launch Velocity To: magnitude((game.Mouse.Position.X- self.Position.X ),( game.Mouse.Position.Y - self.Position.Y ))

    This will calculate the launch velocity as the difference between the 'gun' and the mouse. Instead of the left side of the scene.

    Have fun with the project!

    RThurman
  • ChessPawnChessPawn Member Posts: 127
    I don't understand what you're saying in the second last post. What do you mean by arking from below the ninja. In my ninja system, I have the dots set to spawn by hand starting with the center of the ninja, and +16 every time, keeping Y the same. However, they don't move to the left like I want them to.

    In the gun system, with automatic spawning, they move to the left, but the dots don't start from the middle of the gun, and +16 every time.

    How can I get this picture:

    http://i54.tinypic.com/nyy0ht.png

    To look like this one:

    http://i53.tinypic.com/24cv59d.png

    **Ignore the fact that one is going left and one going right. I'm talking about the dots! :P

    Thanks!
  • ChessPawnChessPawn Member Posts: 127
    BUMP
  • ChessPawnChessPawn Member Posts: 127
    Should I start a new thread for another question I have, or should I put it in this one?
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    ChessPawn said:
    I don't understand what you're saying in the second last post. What do you mean by arking from below the ninja. In my ninja system, I have the dots set to spawn by hand starting with the center of the ninja, and +16 every time, keeping Y the same. However, they don't move to the left like I want them to.

    Sorry about the delayed reply. (Busy weekend!)

    You can still 'hand spawn' the dots. The issue isn't that they were automatic or by hand. What I was trying to say was that the close spacing was to show you the principle of how they worked.

    Just set them to spawn from the left side of the scene every 30 pixels or so (in any way you want). The fewer the dots, the fewer that will be directly under the ninja.

    With less dots, you will get less of them directly underneath the player.

    Also I was saying that if you set the player back to the bottom of the scene, then any low dots will be hidden behind the ninja. (If the ninja is layered above of the dots.)

    Hmmm.....If you are not getting the effect(s) you want, then you might not want to be using the demo as a basis of your game.

    The demo is what it is! However, I hope you have learned a lot from it. While I did not make it, I think it has a lot of great techniques and studying it can give some great clues on how to do things. (So, whoever made it --- thanks!)

    RThurman
  • ChessPawnChessPawn Member Posts: 127
    Wait, wait wait. Hold on a second. I'm not complaining about the fact that I had 120 dots or whatever. My problem is, if I hand spawn them, the part where I replace -10 with 50 doesn't make them go to the left. So really, automatic spawn is the only thing that works, and I can still keep the -10 as -10. But I want the dots to start in the centre of the actor, like what happens when I hand spawn, which doesn't happen with auto spawn. Finally, I have no idea what you mean by dots underneath the ninja, and low dots, and how less dots has anything to do with it.

    Also, I am only using the demo for the super complicated formula.

    I bet I'm sounding extremely stupid right now, but I just don't get it. :P
Sign In or Register to comment.