Trigonometry Fail! Help!

About Monkey 2 Forums Monkey 2 Programming Help Trigonometry Fail! Help!

This topic contains 5 replies, has 3 voices, and was last updated by  therevills 1 year, 4 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #11960

    therevills
    Participant

    I’m trying to shoot a bullet out of hard point which is an offset of the main ship, but my trig is failing 🙁

    Here is some cut down runnable code, I would like the bullet to come out of the red square:

    W = Move forward
    S = Move Backward
    A = Rotate Left
    D = Rotate Right
    Space = Shoot

    Could someone please let me know where I am going wrong?

    #11964

    AdamStrange
    Participant

    Here you go…

    [/crayon]

    The matrix stuff was making things hard for you, so I took it out so you can see the trig in operation. You can add the matrix stuff back once you get familiar with it 😉

    #11972

    Jesse
    Participant

    Is this what you wanted?
    I marked everything I modified.
    the rotation formula was wrong.

    [/crayon]
    #11978

    therevills
    Participant

    Thanks Guys 🙂

    Yep that looks perfect Jesse – I’ve done this sort of thing before in BlitzMax but couldnt work it out! Looks like I was doing everything clockwise instead of anticlockwise, not sure about the 90 degree turn though you do (Pi / 2)?

    #11982

    Jesse
    Participant

    Yea, I got kind of lazy and was just doing some quick modifications because of the results I was getting. I am sure you can figure out the proper way to do it. Basically the problem was in the rotation formula.

    [/crayon]

    you didn’t have offy on the second line you had ofx on both sides of the formula.
    Also, you forgot to add the position(x,y) of the bullet to the direction(dx,dy). about the -Pi/2, the Pi/2 is what you started off in the sprite. I am not sure I can explain it to you but you start with the sprite “Field r:Float = Pi/2” and then your RotationDisplay has an offset angle of 90 degrees. so thats why the adjustment of -Pi/2, at least that’s what I got out of it.

    [EDIT]

    This is more like it:

    [/crayon]

    still have to do the Pi/2 to the shoot direction. but this time its because its shooting 90 degrees from the direction it was created.

    #11983

    therevills
    Participant

    Ah thanks Jesse! Yeah that makes sense!

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.