
-----------------------------------
ZeroPaladn
Thu Sep 14, 2006 12:33 pm

Following the mouse...
-----------------------------------
I was wondering how to make lets say... a bullet go in the directoin of the mouse when fired? I'm at a loss on how to do it. I've heard of using trig and the x and y coords of the mouse and the player and use the pythagoream theorm, but im still at a loss.

PS. Its been a while everyone.

-----------------------------------
Cervantes
Thu Sep 14, 2006 1:13 pm


-----------------------------------
Yes, trig and Pythagorean theorem will be needed. What have you got so far?

Draw these things out on paper. It's a lot easier to work out the equations there than type them immediately into your code.

-----------------------------------
MysticVegeta
Thu Sep 14, 2006 1:24 pm


-----------------------------------
Well you will need Pythagoreans for the shortest distance (hypotneuse) between the bullet and the mouse (x, y). And the trig to figure out what angle it should be shot at. It would be a right triangle so you can use your sin, cos and tan no prob

-----------------------------------
ZeroPaladn
Fri Sep 15, 2006 11:42 am


-----------------------------------
good idea cervantes, ill draw it out, and see what i come up with then. so let me get this straight, i use the pythagorean therom to find the shortest distance between my char and the mouse coords, then figure out the angle of that using trig, then fire off the bullet in said direction?

-----------------------------------
do_pete
Fri Sep 15, 2006 12:23 pm


-----------------------------------
Well you will need Pythagoreans for the shortest distance (hypotneuse) between the bullet and the mouse (x, y).
Why do you need to find the shortest distance? Don't you just need the coordinates of the mouse and character to calculate the angle?

-----------------------------------
BenLi
Fri Sep 15, 2006 12:33 pm


-----------------------------------
actually, you will only need trig if you actually have to know what angle fired at. See what I said at this silmilar post 

http://www.compsci.ca/v2/viewtopic.php?t=13473

-----------------------------------
ZeroPaladn
Mon Sep 18, 2006 12:12 pm


-----------------------------------
if only i understood the code... DAMN I HATE TRIG!

-----------------------------------
Ultrahex
Mon Sep 18, 2006 3:40 pm


-----------------------------------
There Is Also This Way Using Getting The Angle... Here is an example program I just wrote cause i was bored and am procrastinating other assignments


View.Set ("offscreenonly")
var mx, my, mb : int %Mouse Variables
var bulletx, bullety : real := 50.0 %Bullet Location
var velx, vely : real := 0 %Bullet Velocities (Split into x and y)
var pointx, pointy : int := 50 %Point Shooting From
var tempx, tempy : int %Used to Get Point End of Line Drawn from Shooting Point

% Function Written By Ultrahex to Determine Angle in Degrees (Also Includes Exceptions)
% This Code is NOT efficiently Written !!!
function getAngle (x1, y1, x2, y2 : int) : real
    if ((x2 - x1) ~= 0) then
        if ((x2 - x1) 