check collision from one axis

How to check collision from one axis

Some Thing Like That And Thanks For Down Vote No Problem With that

function OnCollisionEnter.y(collision : Collision){
//Do SomeThing
}
i tried that and no Work

i have the same problem man. i just want to chek if my player has collision on its left or right side so that if it does , then destroy it . but donno what to do. did you fixed it ? or have u any idea?

function OnCollisionEnter(coll : Collision){

	for(var c : ContactPoint in coll.contacts){

	var myX : float = coll.contacts[0].point.normalized.x;

	}
}

the easiest solution for you (notice I didn’t say the most efficient)
Would probably be to create 2 collision planes. instead of 1 collision box.

Make them a child of the player and place them on the left and right relative to the player and then they will just move with the player

so

left collision plane position is 1 unit left of the player position (or 2 or whatever amount is just barely left of the player)
right colliison plane postion is 1 unit right of the player position

Now you have 2 seperate objects

OnCollisionEnter(collision : left_collision_plane)

OnCollisionEnter(collision : right_collision_plane)

make sense?

Well after banging my head against the proverbial brick wall that is this problem for hours, I came across this thread…which due to @elbarky’s seemingly-poor English, and lack of describing the problem clearly, was met with disdain (and understandably so). But in his/her defence, this is a problem that can be described pretty easily without much detail of a particular scenario

The solution I finally found with @walkingunity’s help (thanks for leading me on to the correct path!) is one simple line of code:

if (Math.Abs(collision.contacts[0].normal.x) > 0.5f) {
//Yay! We detected collision on the x axis only! Who cares about that pesky y axis?? :P
}

Of course if you wanted to ignore the x axis instead, you could simply use .y in place of .x.

Btw, if it really makes a difference, my scenario was being able to move a sprite horizontally, allowing it to bump into other objects and change direction. But if it falls off a ledge, so what?? Don’t need it to bounce or anything, just keep on truckin’ along that x plane! :stuck_out_tongue: