Path To The end Of The Screen
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.
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.
Comments
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.
http://tinypic.com/r/2njeydz/7
This should answer most questions… Or maybe not!
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!
EDIT: Using the formula above, the dots don't move...
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
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
EDIT: Here's the video
http://tinypic.com/r/2lca13n/7
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".
http://i54.tinypic.com/xn85dj.png
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.)
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
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
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
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
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
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!
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
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