Jump to content

Recommended Posts

Posted

Basically i have my little car goin around but if it hits the sides it doesnt do anything i want it to move to another keyframe. If anyone flash experts know the codes then please help meee!!

 

Thankz:P

Posted

I'm not particularly a flash expert, but collision detection is pretty much the same whatever language. You need some form of script to monitor the objects, and see when their boundaries cross/touch.

 

This video may help:

 

[ame=http://www.youtube.com/watch?v=iUbX9tFtqTg]YouTube- Flash AS3 Collision Detection[/ame]

  • Thanks 1
Posted

is it as2 or as3?

When you move the car you want to get it's x and y position. Then use an if statement so that:

 

if(car.x < 0) {

// hit the left wall

} else if(car.x > Stage.width) {

// hit the right wall

}

if(car.y < 0) {

// hit the ceiling

} else if(car.y > Stage.height) {

// hit the floor

}

 

You can adjust the values to take into account the car's width by using this instead:

 

if(car.x-(car.width/2) < 0)

 

 

Failing that use the hitTest method, placing movieclips around the outside. Check the Flash help for hitTest

Posted

you need the hittest i.e.

 

if (car.hitTest(line1)) {

gotoAndStop(2);

}

if (car.hitTest(end)) {

gotoAndStop(4);

}

};

 

Instead of goto and stop, you could have nextFrame

 

Send me your email address, and I'll email you some working code as a demonstration!

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...