Results 1 to 23 of 23

Thread: Questions, Questions

  1. #1
    Zaei
    Guest
    Something similar to what i was asking earlier. I have one point, which is the current position, and I have a destination (this is in 2D). What i want to do is first, get an angle, so that the actor at point 1 is looking at point 2, and second, have the actor move until its at (or somewhere close, using singles/floats) the destination. Any help is most definately appreciated. Also, my method of choice for movement is to use sin() and cos(), like this: CurrPos.X + cos(facing), CurrPos.Y + sin(facing), but anything will do =). Thanks much.

    Z.

  2. #2
    VirtuallyVB
    Guest
    Your angle "facing" is my angle "Theta".

    You need to scale your CurrPos.X + cos(facing), CurrPos.Y + sin(facing) terms by the distance between the two points (the start and end points).

    Let's call that r
    r = sqrt( deltaX^2 + deltaY^2)

    so
    CurrPos.X + rcos(facing), CurrPos.Y + rsin(facing)

    but you still need the angle "facing" (i.e. Theta) from the previous thread.

    So, yes, get the angle "facing" first,
    then "look" in that direction--you might want to rotate your image and/or use a reflected image (left facing versus right facing),
    then apply the motion using CurrPos.X + rcos(facing), CurrPos.Y + rsin(facing)

  3. #3
    Zaei
    Guest
    One problem was that i wasnt getting a correct theta from the formula that you posted earlier. Maybe i got the implementation wrong, so let me post some code:
    Code:
    SetFacing(UNRAD * atan(myVelocity.z / myVelocity.x));
    ..where myVelocity = DestPos - CurrPos (both Vectors).
    And of course, UNRAD = 180 / 3.14159. I check to see if I'm at the destination by using the 2D distance function. I also implemented this is 2D with a quick VB thing, and when i clicked, my little dot just zoomed away. Am I doing something wrong? I hope so, so that i can fix it =). Thanks for helping out.

    Z.

  4. #4
    VirtuallyVB
    Guest

    Question How many axes are in your 2D project?

    You've been insisting that this is 2D, and you even mentioned X and Y. Now I'm seeing Z.

    Also, velocity is a change in position with respect to time. Unless you have timed the updates of redrawing, your "myVelocity" may be scaled badly (hence zooming off of the screen).

    Your formula should give you an angle between 0 and 90 degrees. Is that what you are expecting (Quadrant I)? I haven't dabbled in VB for a while, but a popular function handles all quadrants. I'm assuming it's available in VB (atan2, atn2, ArcTangent2)? You would have to check the signs to determine the correct quadrant if you don't have an atan2 function.

  5. #5
    Zaei
    Guest
    It is 2D, because im disregarding y(up) for movement, and such. Sorry for the confusion. Makes things a whole lot easier, just to talk in X and Y. I normalized myVelocity, so it should be correct, but that wasnt a symptom before i actually converted the MOVEMENT to use Sin and Cos. Then the zooming started. As you said, i need to scale those, so thats fine. Its just that it never goes in the right direction =(.

    Z.

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    if you really insist using angles, here's how
    http://forums.vb-world.net/showthrea...ghlight=arctan
    but i'd rather get the unitvector with (V1-V2)/|V1-V2|
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7
    Zaei
    Guest
    Thanks kedaman (again =). I noticed that link to the geometry tutorial, so im going to take a gooooood look at that =). And thanks for the tip, I think ill be able to figure it out from there =).

    Z.

  8. #8
    Zaei
    Guest
    The DotProduct of 2 vectors gives theta expressed in radians, correct?

    Z.

    [edit]
    Change the question to "When my DotProduct returns something above 1 (or below -1), how can i get it between those values?" Thanks.

  9. #9
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I posted something like this and all I got was "I'll post some code later." and some links - all but one were broken. You like him better .



    Ps. Zaei, how are the modules coming?
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  10. #10
    Zaei
    Guest
    Please? =).

    Z.

  11. #11
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    yeah but youre working in 2 dimensions zaei? then you can use AngleByOffset i posted back there. I don't see why you even bother using degrees
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  12. #12
    Zaei
    Guest
    I need the angle, because im actually working in 3D, but height doesnt matter, so everything is really on a single plane. I need the angle so i can make my actos face the right way before they move =). Last night I got the movement to work, after i read up on Vector math (I was getting the direction by subtracting vectors, not adding). So, all I need now is to figure out how to get the facing angle, for the rotation.

    Z.

  13. #13
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    so i can make my actos face the right way before they move
    huh?

    you want it to rotate before it moves?

    you don't need the angle for the movement, so if you prefer a faster appoach use both a vector and an angle
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  14. #14
    Zaei
    Guest
    Right, my actos =). I just take the acos of the DotProduct, to get the angle, correct? Then, I can just rotate it, and use the direction vector to set the position, and it looks like its walking in the right direction.

    Z.

    PS: Nice sig kedaman =).

  15. #15
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    thanks zaei
    thats the long way round, try substituting the formulas and you'll see you end up with Arcus tangens instead.
    does the thing, rotate, like it has a nose that you can see rotating and pointing in the direction it's going to move?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  16. #16
    Zaei
    Guest
    This is getting ungodly annoying. It moves in the right direction, it stops where i clicked, but it just wont face the right direction! Whats odd is, if i continue to click on the same spot, it reorients itself. Sometimes it goes the right direction, most of the time it doesnt. Can someone tell me what Im doing wrong? The code goes something like this:
    Code:
    VecNormalize(vecPos, myPos);
    VecNormalize(vecDest, GoingToPos);
    r = DotProduct(vecPos, vecDest);
    SetFacing(CurrFacing + UNRAD * acos(r));
    SetFacing just makes sure that the new facing is between 0 and 360.

    Z.

  17. #17
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    how many times do i have to say not to use the freakin dotproduct lol
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  18. #18
    Zaei
    Guest
    It doesnt work with, or without DotProduct =(. I tried, atan, atan2, AngleByOffset... and my actos ( =) still dont face the right way =(. What else might it be (other than me being an idiot =)?

    Z.

  19. #19
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    nothing i guess
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  20. #20
    Zaei
    Guest
    You =P. Im thinking that, since atan returns something from 0-180, i do that, then, if CurrPos.z > DestPos.z, facing = 180 + whatever i got from atan, and if its less then, facing = atan(...). How does that sound?

    Z.

  21. #21
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    sounds like AngleByOffset
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  22. #22
    VirtuallyVB
    Guest

    Question The ArcTangent of what is 180?

    Zaei
    The ArcTangent of what is 180?

    The values I get for atan(x) are
    -90 < atan(x) < 90

    and I don't think the sign from the atan function helps you much for which quadrant you are facing, so it's like getting an answer from 0 to something less than 90 (degrees). If you write code that tests the sign of your rise variable over your run variable, then you will know which quadrant you are in. Also, there is an atan2 function in most languages that will also tell you which quadrant you are in (i.e. will be "facing into").

    If you are in quadrant I or IV then you will be "facing to the right", when you are in quadrant II or III, then you may need a mirror image of the object to "face to the left". For instance, a side-view image may need the mirror image; but a top down view would not need a mirror image. Both views will need a rotation.

    Quadrants are:

    II | I
    ____|____
    |
    III | IV

    2 1
    3 4

  23. #23
    Zaei
    Guest
    ::grins:: I may not know my trig very well, but im not a complete idiot. I know my quadrants and such like =).

    Z.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width