Computer Science Canada

angle help.

Author:  Bunny_Man_OC [ Wed Dec 20, 2006 7:58 pm ]
Post subject:  angle help.

I have an object that i want to fly around a box (the box is a brightblue line. and when it hits a wall, I want it to deflect into another direction.

but the way I have it it juts follows the exact same pattern, (the oattern is only 4 bouces, is very obvious, and very unprofessional looking!)

so i was wondering if anyone could help me figure out a way to fix this, and make it look better.

this is the code I have for the deflection



code:
procedure birdMove
    if rightUp = true and whatdotcolor (bX + (birdWidth div 2), bY) = brightblue then
        rightUp := false
        leftUp := true

    elsif rightUp = true and whatdotcolor (bX, bY + (birdWidth div 2)) = brightblue then
        rightUp := false
        rightDown := true

    elsif leftUp = true and whatdotcolor (bX - (birdWidth div 2), bY) = brightblue then
        leftUp := false
        rightUp := true

    elsif leftUp = true and whatdotcolor (bX, bY + (birdWidth div 2)) = brightblue then
        leftUp := false
        leftDown := true

    elsif rightDown = true and whatdotcolor (bX + (birdWidth div 2), bY) = brightblue then
        rightDown := false
        leftDown := true

    elsif rightDown = true and whatdotcolor (bX, bY - (birdWidth div 2)) = brightblue then
        rightDown := false
        rightUp := true

    elsif leftDown = true and whatdotcolor (bX - (birdWidth div 2), bY) = brightblue then
        leftDown := false
        rightDown := true

    elsif leftDown = true and whatdotcolor (bX, bY - (birdWidth div 2)) = brightblue then
        leftDown := false
        leftUp := true
    end if

    if rightUp = true then
        bX += 2
        bY += 2
    elsif leftUp = true then
        bX -= 2
        bY += 2
    elsif rightDown = true then
        bX += 2
        bY -= 2
    elsif leftDown = true then
        bX -= 2
        bY -= 2
    end if
end birdMove


bX = bird X position
bY = bird Y position
the pic of the bird is square , so i use bird width to place bX and bY in the middle of the pic. so half of birdWidth is the borders of the bird.

when a border hits a wall (whatdotcolor (coordinated) = brightblue) i want it to delfect.

so any ideas???? any help is appreciated.

Author:  TokenHerbz [ Wed Dec 20, 2006 8:06 pm ]
Post subject: 

deflect? like go in the opposite direction?

you need to make the +velocity go -, or - velocity go + for the approperiate x,y chords.

velocityX *= -1

Author:  Bunny_Man_OC [ Wed Dec 20, 2006 8:29 pm ]
Post subject: 

TokenHerbz wrote:
deflect? like go in the opposite direction?

you need to make the +velocity go -, or - velocity go + for the approperiate x,y chords.

velocityX *= -1


I need it boucne and change direction, but the way i have it it goes in a direction, and then when if bouces it will juts bounce off the other 3 walls and end up exactly where it started, and i want it to do more than that, so i thought that there has to be a way to make it bounce a little differently so that it doenst end up at the same point every 3 or 4 bounces.

Author:  Bunny_Man_OC [ Wed Dec 20, 2006 8:33 pm ]
Post subject: 

Bunny_Man_OC wrote:
TokenHerbz wrote:
deflect? like go in the opposite direction?

you need to make the +velocity go -, or - velocity go + for the approperiate x,y chords.

velocityX *= -1


I need it boucne and change direction, but the way i have it it goes in a direction, and then when if bouces it will juts bounce off the other 3 walls and end up exactly where it started, and i want it to do more than that, so i thought that there has to be a way to make it bounce a little differently so that it doenst end up at the same point every 3 or 4 bounces.


but after thinking about it, what i have will work, but my area is a square, and that is what i think my problem is. if i make the box a rectangle, it should work

Author:  TokenHerbz [ Wed Dec 20, 2006 10:34 pm ]
Post subject: 

perhaps try useing real variables, and Multiply by not a whole 1, but RandInt(.1, .6), Iv'e never tryed it, and its to late to test, but its worth a try. I think it would project a different path each time it hits somthing.

If you want a more specific deflection, like one would want for pong (depending where on the paddle the ball hits and which way the paddles going), It would involve alot more math.


: