PDA

View Full Version : [help]platform game,character stops earlier before collision to right wall



ash_at_risk
November 29th, 2009, 01:01 AM
hi guys,
I m under the process to create a platform based game,but stuck in a problem ,its probably concern with x-axis, actually my player stops certain distance before right wall and with left wall too,i tried to reduce the distance but end up in failure,i have attached the concern fla.


function moveman(Char:Object, timediff:int)
{
if(timediff<1)
return;
var vertical:Number=Char.dy + gravity*timediff;
if (vertical>15.0)
vertical=15.0;
Char.dy+= timediff*gravity;
var horizontalDist:Number=0;
var newDirection:int=Char.direction;
var newAnimstate:String="stand";
if (Char.moveLeft)
{
horizontalDist=-Char.walkspeed * timediff;
newAnimstate="walk";
newDirection=-1;
}
else if(Char.moveRight)
{
horizontalDist=Char.walkspeed*timediff;
newAnimstate="walk";
newDirection=1;
}
if(Char.jump)
{
Char.jump=false;
Char.dy=-Char.jumpspeed;
vertical=-Char.jumpspeed;
newAnimstate="jump";
}

var newY:Number= Char.mc.y + vertical;
var newX:Number= Char.mc.x+ horizontalDist;
Char.inAir=true;
for (var j:int=0;j<wal.length; j++)
{
if ((Char.mc.x+Char.width/2 >wal[j].leftside) && (Char.mc.x-Char.width/2<wal[j].rightside))
{
if ((Char.mc.y <= wal[j].topside)&& (newY>wal[j].topside))
{
newY=wal[j].topside-Char.width;
Char.inAir=false;
Char.dy=0;
break;
}
}
}
for (var j:int=0; j<wal.length; j++)
{
if((newY>wal[j].topside)&&(newY-Char.height<
wal[j].bottomside))
{
if (( (Char.mc.x- Char.width/2) >=wal[j].rightside) && ((newX-Char.width/2 )<= wal[j].rightside))
{
newX=wal[j].rightside + Char.width/2;
break;
}
if(((Char.mc.x+Char.width/2)<=wal[j].leftside) && (newX +Char.width/2>=wal[j].leftside))
{
newX=wal[j].leftside-Char.width/2;
break;
}
}
}
Char.mc.x=newX;
Char.mc.y=newY;
}

dandylion13
November 29th, 2009, 01:19 AM
Is this bit of code correct?

if((newY>wal[j].topside)&&(newY-Char.height<
wa[j].bottomside))


It looks like there's an "l" missing from "wal" ...?

ash_at_risk
November 29th, 2009, 01:42 AM
Sorry i have corrected it.Rest is fine

dandylion13
November 29th, 2009, 03:37 AM
Are your "wal" objects perfectly centered at 0,0 ?

ash_at_risk
November 29th, 2009, 03:55 AM
I accidently discovered what a blunder i did, Inside my actionscript panel i mentioned object man width=50;
man.width=50;
but in the properties panel of flash, i mention
man.width=15.6;
I was thinking of man.width=15.6 , but everytime it get a value man.width=50;
Finally everthing is almost correct
Thanks a ton dandylion

dandylion13
November 29th, 2009, 04:06 AM
Cool, glad you found it :)