Vector Movement - How to detect angle of wall?
I'm trying to a build a racing game in MMF2, in which the player's kart moves using the built the built-in Vector movement. This movement has an action called "Force bounce," but it requires that you input the angle of the surface it collides with. Because of this, it would seem that I'd have to make all of my walls active objects, which would be really taxing on resources.
Is there a way to determine the angle of a backdrop wall when the kart collides with it? (i.e. using detectors and such.) At the moment, I'm having the kart switch to the Bouncing Ball movement whenever it approaches a wall, but that's not my ideal solution since it only has 32 directions and makes for some wildly inaccurate bouncing.
Re: Vector Movement - How to detect angle of wall?
You could run a loop to look around the object and use the Frame Object's "Test for Obstacle at X, Y"
Re: Vector Movement - How to detect angle of wall?
I figured it would involve something like that. In order to achieve this, would I run the loop 360 times around the object and have it take note of when it overlaps a backdrop? If so, what kind of equation would I use to figure out the angle of the surface?
Here's an example diagram of what I'm aiming at:
http://img836.imageshack.us/img836/8941/angler.png
The triangle is a backdrop object, and the circles are karts. Both karts are on a collision course with a surface that's tilted about 30 degrees. No matter what angle the kart approaches the backdrop at, they would need to determine that the surface they're about to hit is 30 degrees.
What might make this tricky is that the Force Bounce action asks you to input an angle that's relative to the frame, not the object itself.
Re: Vector Movement - How to detect angle of wall?
Well, once you find the overlap, you're pointing at the surface. Once you have that you can add 90 to find the angle and/or add 180 to find the normal angle.
"relative to the frame, not the object itself."
There's a difference? :O
Re: Vector Movement - How to detect angle of wall?
Okie dokie. I tried experimenting with the concept like so:
http://img710.imageshack.us/img710/4201/angle2p.png
The black arrow represents the direction that the kart was travelling in before the collision. The blue crosshairs are the coordinates that are being tested, and during the loop, I have them "rotate" around the kart until the coordinates of both crosshairs overlap an obstacle. Once they do, I grab the angle.
It's a start... but unfortunately, it doesn't take into account how much the kart has sinked into the wall. In order for this to remain secure and accurate, I would need to figure out a way to instantly push the kart back out of the wall before I perform the loop. I could just reverse its direction while reducing speed, but that's not instantaneous.
Re: Vector Movement - How to detect angle of wall?
Holy wow, I finally got it working after scratching my head all day. :'D It's a rather creative concept too, so I decided to upload the solution and share it with anyone else who might have a similar problem in the future:
http://games.galaxytrail.com/vector_angledetector.zip
Re: Vector Movement - How to detect angle of wall?
Thanks for that Strife.
Marv