|
-
-
Intermediate Game Dev
Wouldn't it be easier to just have something like this:
Code:
onClipEvent(enterFrame)
{
if (this.hitTest(_root.character) == true)
{
_root.character._x += 10 //as long as it is on the left-ish side. Note that the
//10 has to be higher then the characters normal
//speed, else it goes through the walls.
}
}
I think that should work...just remember to change the _root.character._x to something like _root.character._y if the wall goes across.
-
Character Code
Well that didn't really work; perhaps I should give you the code of the character:
Code:
onClipEvent (load) {
root.up
root.down
root.left
root.right
XSpeed = 6;
}
onClipEvent (enterFrame) {
if (Key.isDown(87) && _root.up == true) {
_rotation = 270;
_y-= XSpeed;
}
if (Key.isDown(83) && _root.down == true) {
_rotation = 90;
_y+= XSpeed;
}
if (Key.isDown(65) && _root.left == true) {
_rotation = 180;
_x-= XSpeed;
}
if (Key.isDown(68) && _root.right == true) {
_rotation = 0;
_x+= XSpeed;
}
}
Last edited by 1337Phantom-I; 08-01-2008 at 08:46 PM.
-
Working On An Online RPG
the reason your fifth wall is not working is because you are using _root.left = true and false, but if you are using the same value on two different walls it will change both of the walls values, so because both walls can never touch the character at the same time, whenever you hit left wall number 1, it will try and make _root.left = false, but then because the other wall is not touching the character, it will make _root.left = true and overwrite the false so you will be able to walk through the wall
in short... find another method rather than using true's and false's since sooner or later you will run into problems... in your case, its sooner
pseudobot's code will work, as long as it is implemented correctly like so...
character code:
Code:
onClipEvent (load) {
XSpeed = 6;
}
onClipEvent (enterFrame) {
if (Key.isDown(87)) {
_rotation = 270;
_y-= XSpeed;
}
if (Key.isDown(83)) {
_rotation = 90;
_y+= XSpeed;
}
if (Key.isDown(65)) {
_rotation = 180;
_x-= XSpeed;
}
if (Key.isDown(68)) {
_rotation = 0;
_x+= XSpeed;
}
}
wall code (in this case left, edit for other walls):
Code:
onClipEvent(enterFrame)
{
if (this.hitTest(_root.character) == true)
{
_root.character._x += _root.character.XSpeed
//it CAN be exactly equal to the character's speed
}
}
-
TY the code works great; although I did ran into another problem along the way with the walls. I want my character to not be able to go through the "fifth wall" from neither sides (right,left,top and bottom). The problem is when I put the code for all sides into the wall; it starts to have complications...
-
Working On An Online RPG
yeah, it would because its trying to move the character in 4 directions that all cancel out... it would kinda spasm
to fix that you can have 4 separate movieclips that make up your wall (thats how i would have done it years ago, but now i am wondering if there is a better way)
anyway, if i figure something else out i will keep you posted, otherwise its 4 movieclips im afraid
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|