Posted By
|
Message
|
Banbeano
Registered 04/03/2008
Points 5
|
22nd December, 2008 at 00:51:46 -
im trying to make a platformer in which the player aims their gun with the mouse. Instead of using bullets, I wish to use an instant hit system. The problem I am having is that I cant figure out how to check for collisions between my line of sight (Im right now using a long 1 pixel wide active.). I am trying to get the line of sight to check for collisions between it, and everything else. My ultimate goal is to have a laser-sight type of setup, where an active is placed on the near side of any obstacle that the player is pointing at.
Sorry if this is confusing, but its hard for me to explain.
n/a
|
-J-
Registered 05/10/2008
Points 228
|
22nd December, 2008 at 06:18:22 -
First you'd need a 360 degree aiming method, so it would always point at the mouse. Then I guess you could use fastloops to send an object towards the mouse and stop when it hits something... :S If you get the loop to move it one pixel each loop, then make the loop run like 600 times, then just check for the collision inside the loop, so
>On loop
>Aimer is overlapping backdrop
-Stop loop
Or something like that, I'm just making this up as I go along as I'm not on a computer with MMF at the moment but I hope this helps
Edited by -J-
n/a ...
|
Banbeano
Registered 04/03/2008
Points 5
|
22nd December, 2008 at 19:39:42 -
There has to be a simpler way. With everything else going on in the game, the way you purpose might cause lag.
I was thinking of a more mathematical way. If I could check for my line of sight intersecting with an object, I could just place the pointer right where I need it.
Edited by Banbeano
n/a
|
-J-
Registered 05/10/2008
Points 228
|
22nd December, 2008 at 23:15:26 -
Here's a method that uses a loop, I tried it in mmf2 and it works pretty fine to me :S You need an object to be the laser sight, like a little red dot or something. I've just called it "Dot".
> Always
- Start loop "aim" Sqr((X( "Player" )-XMouse) pow 2+(Y( "Player" )-YMouse) pow 2) times
The bold code just checks the distance between the mouse and the player
> On loop "aim"
- Set Dot's X position to: X( "Player" )+Cos(ATan2((YMouse-Y( "Player" )), (XMouse-X( "Player" ))))*LoopIndex("aim")
- Set Dot's Y position to: Y( "Player" )+Sin(ATan2((YMouse-Y( "Player" )), (XMouse-X( "Player" ))))*LoopIndex("aim")
> On loop "aim"
+ Dot is overlapping a backdrop
- Stop loop "aim"
And that should work perfectly! I borrowed some of that code from an AI article, where the enemy would just calculate distance and angle from itself to the player, and if there was an obstacle in the way. I figured it could be used to calculate the same stuff from the player to the mouse so yeah.
Here's an example I made:
http://download326.mediafire.com/f5d1mjmm4ytg/motmjmymzqj/Laser+Aiming.mfa
Hope this helps
Edited by -J-
n/a ...
|
Banbeano
Registered 04/03/2008
Points 5
|
22nd December, 2008 at 23:56:34 -
That helped a lot. Exactly what I needed.
n/a
|
-J-
Registered 05/10/2008
Points 228
|
23rd December, 2008 at 00:04:35 -
Of course if you didn't want the dot to stick to the mouse, and be projected beyond the mouse until it hit a wall, you could use the fastloop object and run the "aim" loop an infinite (-1) number of times. I tried this but noticed that sometimes the application would crash if my player moved inside a backdrop :S
n/a ...
|
|
|