|
-
Apr 19th, 2001, 05:52 PM
#1
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.
-
Apr 19th, 2001, 08:22 PM
#2
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)
-
Apr 19th, 2001, 08:42 PM
#3
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.
-
Apr 19th, 2001, 10:31 PM
#4
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.
-
Apr 20th, 2001, 05:54 AM
#5
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.
-
Apr 20th, 2001, 04:38 PM
#6
transcendental analytic
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.
-
Apr 20th, 2001, 04:49 PM
#7
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.
-
Apr 20th, 2001, 05:26 PM
#8
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.
-
Apr 20th, 2001, 05:54 PM
#9
Good Ol' Platypus
-
Apr 20th, 2001, 06:57 PM
#10
-
Apr 21st, 2001, 05:14 AM
#11
transcendental analytic
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.
-
Apr 21st, 2001, 11:27 AM
#12
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.
-
Apr 21st, 2001, 11:33 AM
#13
transcendental analytic
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.
-
Apr 21st, 2001, 01:15 PM
#14
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 =).
-
Apr 21st, 2001, 01:22 PM
#15
transcendental analytic
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.
-
Apr 22nd, 2001, 01:34 AM
#16
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.
-
Apr 22nd, 2001, 01:49 AM
#17
transcendental analytic
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.
-
Apr 22nd, 2001, 02:29 AM
#18
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.
-
Apr 22nd, 2001, 02:42 AM
#19
transcendental analytic
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.
-
Apr 22nd, 2001, 03:09 AM
#20
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.
-
Apr 22nd, 2001, 01:52 PM
#21
transcendental analytic
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.
-
Apr 24th, 2001, 10:21 AM
#22
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
-
May 16th, 2001, 12:50 PM
#23
::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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|