setting an objects direction in 360 degrees
I am currently setting an object's direction to be equal to a variable, so that I can take advantage of MMF2's inherant 32 directions. (Example: if the var = 16, then the object's direction is set to 180 degrees.) This is great for most of my needs, but I am finding that for some things, I would like to have more angles to work with than 32. I imagine I should be looking at the Advanced Direction object, but it is confusing me a great deal.
Ideally, I still want to be able to set the direction by reading the value of a variable so that it represents an actual degree value. (Example: if var = 180, then the object's direction is set to 180 degrees, var = 190, then object's direction is set to 190 degrees, etc)
Is there a relatively non-complicated way to achieve this? :blush:
Thanks,
Mobichan
Re: setting an objects direction in 360 degrees
Instead of using directions, simply use 360 degree angles. Even better, in the HWA beta it supports float angles instead of integers for even more directions and accuracy.
Re: setting an objects direction in 360 degrees
Since I am using the Bouncing Ball movement, setting a direction is the simplest way to get movement for me right now. Setting angles seems to just rotate each object, but not control the direction it travels in.
I am asking if there is a way to set up my directions to use angles? As for HWA, I'm not making this for the web, so sadly I can't tap into that. :(
Re: setting an objects direction in 360 degrees
You can control the direction your object travels using angles and simple trig. And I'm not sure if you understood what I meant by HWA, Hardware Acceleration, which just renders things differently, it has nothing to do with the web. You must be thinking of Java or Vitalize.
Re: setting an objects direction in 360 degrees
Sorry, for some reason I have it in my head that HWA = Vitalize. Oops... As for that "simple trig", I guess that is what I am asking for an example of.
Re: setting an objects direction in 360 degrees
All you need is:
Set X to X("Active")+Sin(Angle("Active"))*Speed
Set Y to Y("Active")+Cos(Angle("Active"))*Speed
That makes it so that the object travels in the direction of its angle. You might have to add or subtract 90 from the angle to make it travel in the right direction.
Re: setting an objects direction in 360 degrees
Thanks. So since the speed is calculated from the Bouncing Bullet, do I still need to set it? Or is this method abandoning the movment setting (and I should be using a static movment)?
Re: setting an objects direction in 360 degrees
I'm not really sure what your doing in your application. The trig equations I mentioned before will make the object travel in a straight line if their angle is not changed. If your making a bouncing bullet, I don't think those would apply, depending on how it is set up.
Re: setting an objects direction in 360 degrees
Here is my test file:
bullet test
The active group shows the simplest use of my directional code. I need to determine if there is a simple way to integrate the formulas you just posted.
Sorry if I am asking too many questions, but I have trouble really understanding how to apply trig in this situation.
Mobichan
Re: setting an objects direction in 360 degrees
I made an example a while ago on how to make custom guns in games. I took that example and stripped it down to what you need. Click to shoot and change the values to what you want. Range is how far the bullets spread out. There may be unnecessary things in the application because I basically just gutted it to what you need. The equation in the Shoot Loop line is the one that spreads them out: Angle( "Player" )+(value( "Angle Range" )/value( "N Of Bullets Per Shot" )*((value( "N Of Bullets Per Shot" )/2)-LoopIndex("Shoot")))
Link: Gun Test
Re: setting an objects direction in 360 degrees
The link seems down, so I'll try downloading later tonight.
Thanks,
Mobichan
Re: setting an objects direction in 360 degrees
Ok, its fixed. The link should work now.
Re: setting an objects direction in 360 degrees
Thanks for the example. It makes me curious about using the Movement Controller more, since it has the ability to work with angles. Unfortunately (as with most examples) it uses the mouse pointer as one set of points in the equation. This will probably come in handy for future projects, but since I am using this for enemy bullets, I need to figure out a way to define a set of points that don't involve the player/mouse.
Maybe I'm not approaching this the correct way, but I have a feeling I should somehow use the enemy's position and an arbitrary point in front of the enemy as a sort of "reference" point. Then at least I will have a starting angle to work from. I noticed the "Convert Direction to Angle" expression. Is it possible to set an initial direction with the standard 32 angles and then convert it to degrees, after which I can work solely in degrees? Or is that for setting the angle and not the direction? :confused: The distinction between the 2 terms is a little confusing.
If only the standard MMF2 directions could have an option to support 32 or 360 directions. Sigh...
Mobichan
Re: setting an objects direction in 360 degrees
It doesn't use the mouse to determine where to shoot. It uses the player's angle, which is exactly what an enemy would use to fire. There is no XMouse or YMouse in the equation. It should be easily adaptable to enemies.
Re: setting an objects direction in 360 degrees
It looks like the initial angle is set as a direction based on 2 points, one of which is the turret and one of which is the mouse x,y. Then that angle is used to determine the shoot direction. Or am I misunderstanding the equations?
Re: setting an objects direction in 360 degrees
Yes, you are misunderstanding the equation, I'll dissect it for you. The original equation is:
Angle( "Player" )+(value( "Angle Range" )/value( "N Of Bullets Per Shot" )*((value( "N Of Bullets Per Shot" )/2)-LoopIndex("Shoot")))
Angle( "Player" ) = Starts off the equation by providing a base angle for the bullets to fire in.
(value( "Angle Range" )/value( "N Of Bullets Per Shot" ) = Spaces out the bullets when multiplied by the next part of the equation. Dividing the range by the number of bullets evenly spaces them out.
((value( "N Of Bullets Per Shot" )/2)-LoopIndex("Shoot"))) = This part is multiplied by the previous part. The reason the number of bullets is divided by two is so that half of the bullets travel above the angle of the player and half travel below. That alone wouldn't work though, because you have to subtract the Loop Number from it, and it loops the number of times that there are bullets, so half of them will be a negative number, and that is subtracted from the angle.
It's a bit confusing, but I explained it the best I could. As you can see, there is no reference of mouse positions. The only thing in there remotely like Mouse Positions would be the angle part at the beginning. This doesn't require any input from the player and is completely set by the angle of the object shooting. So if the enemies travel based on angles, they can fire using this system. Even if they use simple 32 directions, simply dividing by 11.25 (360/32) would put it into 32 direction. The angle of the player is set by the mouse positions, as you can see when you move the mouse the player turns to face it. But if you set the angles for an enemy, you will not be setting it by the mouse and can still use the angles.
Re: setting an objects direction in 360 degrees
Brandon: This really helps me out quite a bit. I am definitely learning there are MANY ways to do the same thing. I actually was stuck on how to recreate this until I realized my bullet's movement was set to bouncing ball and yours was set to vector. It seems that the Bouncing Ball controls are not in the Movement Controller , so I might be out of luck with trying to combine both of our approaches into one system. But I might just use the things you've taught me for more complex enemies like bosses. All in all, thanks for spending the time to work with me on this.
:grin:Mobichan
Re: setting an objects direction in 360 degrees
No problem :) . Glad I could help somewhat.