;

PDA

Click to See Complete Forum and Search --> : Movement question, stop me


ConnELITE
08-05-2005, 02:52 PM
ok, I want to make a box that my character can't go inside of (like it was a rick or someting). I don't want it to bounce off I just want it to stop. I know how to do it but my way is really complacated and time consuming so I'm hoping there is an easier way (if not ill do it my way). My way is that I'd have a box made up of four parts (top,left,bottom,right) and four scripts formatted for each side. Here's the one for the right side:

xdiff=element("Dude").x-element("BoxRight").x
ydiff=element("Dude").y-element("BoxRight").y

xveldiff=element("Dude").velocity.x-element("BoxRight").velocity.x
yveldiff=element("Dude").velocity.y-element("BoxRight").velocity.y

if (xdiff>0)
{totheright=1}
else if (xdiff==0)
{totheright=0}
else
{totheright=-1}



if (xveldiff>0)
{movingfasterright=1}
else if (xveldiff==0)
{movingfasterright=0}
else
{movingfasterright=-1}

if (yveldiff>0)
{movingfasterdown=1}
else if (yveldiff==0)
{movingfasterdown=0}
else
{movingfasterdown=-1}

if (element("Dude").collideRect(element("BoxRight")))
{
collision=1
}
else
{
collision=0
}

if (collision==1 && totheright==-movingfasterright)
{
element ("Dude").velocity.x=0
element("BoxRight").velocity.x=0
collision=0
}

if (collision==1 && below==-movingfasterdown)
{
element ("Dude").velocity.y=0
element("BoxRight").velocity.y=0
}


[COLOR=Black]
I've also noticed if you keep pressing the the key in the direction the of the box, you can work your way through the box. To fix that I just did a code that basically wont let you press the key in the direction if your in collision woith it.

Anyway this is real hard and takes forever to do for each box or item, so please tell me an easier way before I start doing this.
Thanks in advance.

blanius
08-05-2005, 05:59 PM
without actually writing the code for you think it out like this..


if dude collides with box
get current direction by check to see which velocity is not zero and wether
it's negative or positive.

set that velocity to zero and move the object backwards a bit so that it no longer collides


by the way this is how I tend to code complex stuff I write the idea in remarks and then fill in the code to do what I've stated in the comment.