Now I had a working code for this but lost it recently but I have a character you move with the keyboard keys, and I have a wall I want to stop the character when they hit it.
Now the code I had I cant remember but it was really simple, I think it was so when the character ran into it, it had a _x=-4 and _y=-0 or something so no matter how much you tried running into the wall it would just keep pushing the character back not letting them pass through it.
I'm sure at least one of you Guru's in here know what I'm talking about
that doesnt work, that involves moving the character also while my character already has movement on them, I'll put a copy of it in here for you to look at, maybe you'll understand more what I mean, as I'm not the best at explaining
I fixed the problem I was having it was super simple it was simply this
Code:
onClipEvent (enterFrame) {
if (hitTest(_level0.wall1)==true) {
_x=_x-5;
}
}
on the character and the wall has the instance name of "wall" so then you either change it to:
_x=_x-5 for a right wall
_x=_x+5 for a left wall
_y=_y-5 for a lower wall
_y=_y+5 for an upper wall
and just change the 5 to a higher number for more resistence and a lower number for less resistence. Really simple stuff, I found the code at Actionscript.org in Tutorial 47 in the Begining level
Lets say i wanted to have a hitTest but it tests if an object hit part of another object. If i had a square
________
l_______l
l_______l
l_______l
l_______l
and i just wanted the middle 2 sections tested, not the top and bottom part.
Thanks,
The Amoeba
...I know bad drawing lol
Last edited by The Amoeba; 09-12-2005 at 10:55 PM.
Thanks for the reply, however the mouse code is not the problem, I just posted that to let whoever might help see the code I am already using to see if there would be any interferences with that code that makes everything function properly...
The mouse pointer code works fine... the problem is with how to use HitTarget to make the movie clip of the mist in the button of the spray can hit the bugs and make them disappear...
onClipEvent (enterFrame) {
if (this.hitTest(_root.lft)){
_x += 5; }
}
i have the code on the character and oviously i have the rest of the code on how to move, but when the character hits the mc lft it doesnt get hit back 5 pixels right but it just goes under
hey what if i wanted the code for a hittest to be put on the wall? (the last post was like 3 months ago so i dought ne body is gonna reply but thanx if u do)
if the wall is on the right, you'd use
onClipEvent (enterFrame) {
if (this.hitTest(_root.wall)){
_x -= speed; }
}
left would be oppisite. and top and bottom would be with 'y' instead of 'x'.
Here's code I'm quite fond of using for moving the player. It requires a clip on _root, called map containing the areas you're not allowed to walk on (It basically tests the bounding box of the object against an actual shape):
Does anyone know how i can use this code to work in flash 8 or 2004? I tried it at school with MX and it worked fine. When i got home and tried with 8 it did not work. Can someone help/ pm me/ or email [email protected] thanks
Hi,
this seems like THE place to ask problems to do with hit tests, so here i go.
on the attached fla file, ive got a purple box (follows the mouse) and a red box. i tried to make it so the purple box cannot pass through the red box, but i cant do it! sometimes it stops, but if you move the mouse fast it tends to go through. ive been messing with this problem for over a week and i really have no more ideas for a solution, id love it so much if someone can shine some light on how i can do this! id LOVE IT!
(if its possible to stop an MC that is stuck to the mouse pointer from going through the red MC, that would be fine as well, any solution il be so happy for!)
thanks for any help!
this works really nicely for art-based RPG's where you go from room to room, but is there any way to modify the code to make a large outdoor map that will start to scroll up/down/left/right as soon as the "hero" gets to the midpoint of the screen? If you still don't know what I'm talking about here's an example someone did that I'm trying to implement into my RPG engine, but i'm stumped on how to do it using the current script setup: http://www.geocities.com/mclelun/rpg.html
i have some white circle movie clips (instance name limit) in a movie clip called map.
when it hits the limit movie clip i want it to stop, the problem with taht is it scrolls into the circle a bit before stoping (the player and the object partly overlap) and its easy to get stuck.
I want it to stop as soon as one edge ofd the player hits one edge of a wall.
tahts the first thing
the 2nd thing is that i have 7 or something of them circle movie clips in the map movie clip (all instanced named limit), and it only works for one. I need it so i can make many diffrent walls and boundaries of diffrent shapes and locations.
i have some white circle movie clips (instance name limit) in a movie clip called map.
when it hits the limit movie clip i want it to stop, the problem with taht is it scrolls into the circle a bit before stoping (the player and the object partly overlap) and its easy to get stuck.
I want it to stop as soon as one edge ofd the player hits one edge of a wall.
tahts the first thing
the 2nd thing is that i have 7 or something of them circle movie clips in the map movie clip (all instanced named limit), and it only works for one. I need it so i can make many diffrent walls and boundaries of diffrent shapes and locations.
help is apreciated! ive been looking for days.
You don't need to post this twice. I just answered your question here .
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD WEI Score: 7.6