Skip to main content
GameDev.net gamedev.net
🔒 Locked

Weapons

Started by BlackScar Oct 25, 2000 at 11:06 PM 3 replies 150+ views
Original Post
BlackScar
BlackScar
Greetings again! I have two points, the player and the enemy. Now! I need to find out the degree of a line between the two. Did I loose anyone there? Ok! Perhaps I need to tell what I''m doing.... I''m trying to see if I''m shooting an enemy. I''m not using bounding boxes so I need to see if the degree is within the player''s y rotation. If it is then cause damage to the object. This would also be helpful to find out if the bot is facing the player.... if he is then make it go after him. Does anyone know how to do that? Or maybe a better way? Or do I need to be more specific on what I want? Thanks alot! ~-=-=-=-=-=-=~ ~Justin Eslinger~ ~.."BlackScar"..~ ~-=-=-=-=-=-=~
~-=-=-=-=-=-=~~Justin Eslinger~~.."BlackScar"..~~-=-=-=-=-=-=~
wise_Guy
wise_Guy
Okay, to find the angle of the line between two objects (in 2D here, but should be transferrable to 3D), just use trigonometry. Use the difference between the enemy x and the player x to get the horizontal line, and the difference between the y''s to get the vertical, then just use sin or cos to get the hypotenuse, or use inverse sin or inverse cos to get the angle.

Also in 3D you can use 1 type of vector multiplication (i think it is dot product but not sure) and then you use cos which then you can easily check if its behind the player''s FOV depending on what value it is (because cos always fluctuates predictably).

Ahhh it is late and my post is unorganised, but someone with a better memory can explain the vector stuff to you!

later

wise_guy
wolfman8k
wolfman8k
You can use the dot product. But make sure you normalize your vectors.
Staffan
Staffan
The angle between two vectors you''re saying?

T Angle(const gzVector3T& vec) const { return acos(((*this) * vec) / (this->Magnitude() * vec.Magnitude())); }

Where Magnitude() is:

T Magnitude() const { return sqrt(x * x + y * y + z * z); }

"Paranoia is the belief in a hidden order behind the visible." - Anonymous
BlackScar
BlackScar
Ok, if I take the player''s x pos and minus the objects x pos and then do the same for y pos, how can I use that to see if it''s in the player''s fov?

I''d imagine I''d have to use the sin and cos functions, but I don''t understand how to put it all together. (Especially since I haven''t took trig yet )

Thanks Again


~-=-=-=-=-=-=~
~Justin Eslinger~
~.."BlackScar"..~
~-=-=-=-=-=-=~
~-=-=-=-=-=-=~~Justin Eslinger~~.."BlackScar"..~~-=-=-=-=-=-=~

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.