It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Flash Forum

Hit Test probelm

Moderator: Phate

Hit Test probelm

Postby Johnnytron on Mon Apr 23, 2007 4:24 am

Hi there,
I just joined up to this forum, its looks pretty comprehensive, I'm impressed.

I hoping someone here is going to be able to help me,
I'm making a game where you drive a boat around a harbour and have to park the boat in the right area. If you hit anything like other boats or dock/land its game over.
The problem I'm having is the hitTest im using isn't very accurate at all but I can't work out why.

this is code im using to control the boat and its hitTest, it sits on the on the mc_mainboat

Code: Select all
onClipEvent(load)
{
speed =0 ;
}

//control the current strenght
onClipEvent(enterFrame){
_root.imainboat.onEnterFrame=function(){
   this._x-=(this._x-_root.icurrent._x)*.0001;
   this._y-=(this._y-_root.icurrent._y)*.0001;
   }
}
onClipEvent (enterFrame) {
// make the boat go forward
if (Key.isDown(Key.UP)) {
speed += 0.2;
}
// make the boat go backwards
if (Key.isDown(Key.DOWN)) {
speed -= 0.2;
}
// tells the boat to slow down after the speed of 20
if (Math.abs(speed)>10) {
speed *= .3;
}
// you can change the rotation of the boat to your desire
if (Key.isDown(Key.LEFT)) {
_rotation -= speed*0.6;
}
if (Key.isDown(Key.RIGHT)) {
_rotation += speed*0.6;
}
// here is where the hittest is for the boundary
speed *= 0.98;
x = Math.sin(_rotation*(Math.PI/180))*speed;
y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
if (!_root.iland1.hitTest(this)) {
if (!_root.iland4.hitTest(this)){
_x += x;
_y += y;
} else {
speed *= -0;
this.gotoAndStop(5);
}
}
}



Thanks in advance for your help.
Johnny
Johnnytron
 
Posts: 2
Joined: Mon Apr 23, 2007 4:05 am

Postby flabbyrabbit on Mon Apr 23, 2007 6:11 pm

Hellol, and welcome to DEVPPL. What do you mean by its not very accurate?? Would be much easier for you to upload the .fla with this problem so I can see whats happening.

Flabby Rabbit
Image
User avatar
flabbyrabbit
500+ Club
 
Posts: 706
Joined: Thu Jan 25, 2007 1:10 pm
Location: Midlands, England

Postby Johnnytron on Mon Apr 23, 2007 10:09 pm

How do I upload the .fla?
I'm probably missing something obvious here
Johnnytron
 
Posts: 2
Joined: Mon Apr 23, 2007 4:05 am

Postby flabbyrabbit on Tue Apr 24, 2007 10:36 am

Just email me it and ill have a look, nosmo-kings@hotmail.com

Flabby Rabbit
Image
User avatar
flabbyrabbit
500+ Club
 
Posts: 706
Joined: Thu Jan 25, 2007 1:10 pm
Location: Midlands, England


Who is online

Users browsing this forum: No registered users and 2 guests