The McLeodGaming forums were permanently closed on April 30th, 2020. You are currently viewing a read-only archive.
View unanswered posts | View active topics It is currently Fri May 15, 2020 5:41 am

Forum rules


IMPORTANT

This Forum is for Flash related questions ONLY! Do not ask questions about spriting, Game Maker, Photoshop, or anything else not related to Flash.



 [ 3 posts ] 
[Question] Z axis movement? 
Author Message
SSF2 Developer
User avatar

Joined: Mon Aug 11, 2008 2:25 pm
Posts: 968
Location: Around the East Coast of the US
Gender: Male
MGN Username: KingTremolo
Currently Playing: Super Mario 64, Monster Hunter 4, Sonic Generations
Okay, so a game I'm planning on making will have some pseudo 3D parts, so, how do I make someone move in the Z-Axis, and only touch the door when he's at the right spot in the axis, or Size.

_________________
Image


Mon Mar 23, 2009 9:22 pm
User avatar

Joined: Sun Aug 17, 2008 5:39 pm
Posts: 1248
Gender: Anime Girl
Skype: Nacritico
Currently Playing: LOL
you should do a simple collision function:
Quote:
* zCollision*
Code:
function zCollision(object1,object2){
  if(object1.z == object2.z){
    return true
  }
  return false
 }

*allCollision*
Code:
function allCollition(object1,object2){
  zCollided = zCollition(object1,object2)
  xyCollided = object1.hitTest(object2)
  if(zCollided AND xyCollided){
    return true
  }
  return false
}


Now, if you want to be even more complex, you can add a the objects a length (Hight = all y; Width = all x; length = all z); in other words, a value that shows how deep the object is.

*note: I'll have to check the code below, since I wrote it in here, not in flash... so it might contain mistakes*
Quote:
* zCollision*
Code:
function zCollision(object1,object2){
  touching = false
  touch0 = ((object1.z+object1.lenght)>= (object2.z-object2.lenght))
  touch1 = ((object1.z-object1.lenght)<= (object2.z+object2.lenght)) 
  if(touch0 AND touch1){
    touching = true
  }
  return  touching
}

*allCollision* (this one remains the same)
Code:
function allCollition(object1,object2){
  zCollided = zCollition(object1,object2)
  xyCollided = object1.hitTest(object2)
  if(zCollided AND xyCollided){
    return true
  }
  return false
}


Finally, I would suggest you a length checker, in case you forgot to add length to some object

Quote:
* zCollision*
Code:
function zCollision(object1,object2){
  if(object1.length==undefined){
    object1.lenght = 1
  }
  if(object2.length==undefined){
    object2.lenght = 1
  }
  touching = false
  touch0 = ((object1.z+object1.lenght)>= (object2.z-object2.lenght))
  touch1 = ((object1.z-object1.lenght)<= (object2.z+object2.lenght)) 
  if(touch0 AND touch1){
    touching = true
  }
  return  touching
}

*allCollision* (this one remains the same)
Code:
function allCollition(object1,object2){
  zCollided = zCollition(object1,object2)
  xyCollided = object1.hitTest(object2)
  if(zCollided AND xyCollided){
    return true
  }
  return false
}

_________________
SALU2'S Image
_________________
Original forum: show
join date: January 08, 2007
Posts on old MG: 2432, level 16

Image
Image chóu


Wed Mar 25, 2009 1:53 pm
User avatar

Joined: Wed Apr 29, 2009 11:28 pm
Posts: 323
Location: Nowhere, Antarctica
Gender: Anime Girl
Skype: Evilagram
Nac, there are SO many mistakes in that code that I do not know where to begin.

Oh wait, yes I do.

ELSE. USE THE f*** ELSE HANDLER!

Code:
function zCollision(object1,object2){
  if(object1.z == object2.z){
    return true
  }else{
    return false
  }
}


Everywhere, you messed that up. Every single code.

Next is this little gem right here:

Code:
if(zCollided AND xyCollided){


First off, you mean &&, not AND. Second, you need to test them to see if they are true. The correct code here, and in all other instances is:

Code:
if(zCollided == true && xyCollided == true){


Third, you're overcomplicating it by separating it out into variables. Just say this:

Code:
if(object1.z == object2.z && object1.hitTest(object2)){


Next, that's not even close to how to handle a Z collision, unless your objects happen to be sheets of paper, conveniently facing the viewer. I don't have the time to rewrite your code so that it isn't retarded.

_________________
Image

Style [Stayl] (n) - One's unique and personal method of defacing a perfectly good piece of paper.

READ THIS: http://ipgd.freehostia.com/copypasta.html


Thu Apr 30, 2009 1:14 am
Display posts from previous:  Sort by  
 [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software for PTF.