BackDoor- Door 1
You find yourself in a strange house with only a man on the phone as a guide.
4.08 / 5.00 28,197 ViewsMini Commando
Action adventure game with nazi enemies in the second world war.
3.89 / 5.00 24,517 ViewsHow come this code "works":
onEnterFrame = function(){
if(player.hitTest(_root.ground)){
trace("hitting");
}
}
and these don't:
onEnterFrame = function(){
if(player.hitTest(_root.ground._x, _root.ground._y, true)){
trace("hitting");
}
}
onEnterFrame = function(){
if(player.hitTest(_root.ground._x, _root.ground._y, false)){
trace("hitting");
}
}
WTF? I'd use the first one, but that registers hitTests with the bounding box, not the actual shape.
What's wrong?
You have to do it the other way around. The ground's x and y (it's registration point) are at one small point on the ground movieclip (Look for the little 'cross')... so it will only check if the player is hitting that tiny point, and not anywhere on the ground.
What you want to do is put the player's registration point at his feet, and then check the ground AGAINST that.
if(ground.hitTest(player._x, player._y, true))
Perpetually looking for time to return to the arts.
because you're checking the ground's _x, _y not the players, so the player will have to hit the one spot on the ground for the hittest to work
onEnterFrame = function(){
if(player.hitTest(_root.ground._x, _root.ground._y, true)){
trace("hitting");
}
}
try:
onEnterFrame = function(){
if(_root.ground.hitTest(player_x, player._y, true)){
trace("HITTING");
}
} Thanks guys... hitTests are messed up IMO.
At 7/18/09 10:59 AM, Archon68 wrote: Thanks guys... hitTests are messed up IMO.
No, you just don't know how to use them.
At 7/18/09 11:03 AM, CHINESEMANZOMG wrote:At 7/18/09 10:59 AM, Archon68 wrote: Thanks guys... hitTests are messed up IMO.No, you just don't know how to use them.
No, I know how to use them... and I agree with him. It's backwards.
It is more intuitive to check if the player is hitting the ground, not if the ground is hitting the player, so for someone new to programming, that's what they're going to check. If the player is hitting the ground.
In real life, you'd say "Am I standing on the ground?" not "Is the ground keeping me from falling through it"
Blah.. blah.. newton's law, equal/opposite reaction, they're hitting each other I know... but from a basic view, it's more natural to check if the player is hitting the ground.
Perpetually looking for time to return to the arts.
At 7/18/09 11:08 AM, Johnny wrote: It is more intuitive to check if the player is hitting the ground, not if the ground is hitting the player, so for someone new to programming, that's what they're going to check. If the player is hitting the ground.
I'm not new to programming, just annoyed with hitTests, I can never remember which way to use them.
Other than that, I agree with you completely.
At 7/18/09 11:35 AM, Archon68 wrote: I'm not new to programming, just annoyed with hitTests, I can never remember which way to use them.
Please don't argue that.
If you had trouble remembering how to properly use a hitTest, to the point where you had to ask for advice on one of the most basic methods and to not be able to easily figure out that the position of a registration point was the culprit, you're still new enough to actionscript to warrant being called so. It's not an attack at you. It's a reality is all.
If you argue against it, then instead of being 'new'... you're just a little 'slow.'
So you can take 'slow' or 'new'
Your choice.
Perpetually looking for time to return to the arts.
Fine, I'm relatively new to hitTests, just not AS in General.
the entire issue is that you cannot check for contact between the true shapeflags of both objects. You can test a true shapeflag against a bounding box or a true shapeflag against a point. Not a true shapeflag against another true shapeflag, which we game designers need oh so badly.
Very stupid imo, could probably be done by adobe but meh, what are you gonna do?
At 7/18/09 12:16 PM, zedd56 wrote: Very stupid imo, could probably be done by adobe but meh, what are you gonna do?
Implement it yourself. There isn't a mega quick way of just testing any two shapes, it depends on your set up.
Once you start going into vector collision detections, all your hitTest troubles will be gone. Otherwise, just learn how to properly use hitTest and it'll work great 95% of the time.
At 7/18/09 12:30 PM, Coolio-Niato wrote: Once you start going into vector collision detections, all your hitTest troubles will be gone. Otherwise, just learn how to properly use hitTest and it'll work great 95% of the time.
I know bitmap collision detection, but I never heard of vector collision detection..