
-----------------------------------
Randolf Nitler
Thu Jan 10, 2008 12:10 pm

Trajectory problems
-----------------------------------
You probably heard this before, but i have a problem with getting my tanks to shoot at each other at an angle so that the missile curves while traveling towards the other player. So far I have 4 variables: power, angle, playerpositionX, and playerpositionY. Can som1 help me with making a formula that i can use to get my tanks to shoot properly.  I'd also very much appreciate it if you could also code it for me so that i can change it into my variables and have it working. Just a simple demo is all I need. Thanks again.

-----------------------------------
Tony
Thu Jan 10, 2008 12:13 pm

Re: Trajectory problems
-----------------------------------
I'd also very much appreciate it if you could also code it for me
This is against forum rules.

To get the trajectories, you will need to keep track of vertical + horizontal velocities and acceleration. Just like in a typical "throw object from a cliff" type of problems from the Physics class.

-----------------------------------
LaZ3R
Thu Jan 10, 2008 3:51 pm

RE:Trajectory problems
-----------------------------------
lmao, those kind of questions were fun :D. 

Nitler, this isn't a forum where you get answers. Learn how to do things yourself or ask for help instead. No one here will/is allowed to simply post code for you so you can take it and manipulate it for your own usage instead...

If you give a man a fish, he has food for a day. If you teach him how to fish, he has food for life. 

Same idea...

-----------------------------------
Randolf Nitler
Thu Jan 10, 2008 10:19 pm

Re: Trajectory problems
-----------------------------------
I feel so stupid now =/ Alright sorry about that, I've fixed my problem now

-----------------------------------
CodeMonkey2000
Thu Jan 10, 2008 10:27 pm

RE:Trajectory problems
-----------------------------------
It's really not that hard. Once you get the missile to go at the desired angle, then y component of the speed of the missile needs to decrease at a constant rate.

-----------------------------------
Randolf Nitler
Fri Jan 11, 2008 12:16 pm

Re: Trajectory problems
-----------------------------------
Currently this is what i have, and I have 2 little problems with what i have here:
1. If i set angle to 2, or 3 and so on, the missile isnt drawn
2.  if i set angle to 45, notice the missile doesn't start at the exact angle of 45
please help, and show where my mistakes are so i can fix them!


% setscreen size
setscreen ("graphics:1000;500,offscreenonly")

% get the player variables
var player1locationX, player1locationY, radius : int
player1locationX := 15
player1locationY := 15
radius := 15

% draw the player onto the screen
drawfilloval (player1locationX, player1locationY, radius, radius, brightred)
drawfilloval (player1locationX, player1locationY, 3, 3, black)

loop
    % for the missile must go up, and then come down at a certain time
    % put time in a for loop
    for t : 1 .. 100
        delay (200)
        % name missile variables
        var currentXlocation, currentYlocation, power, angle, gravity : real
        gravity := -1
        angle := 2
        power := 20
        currentXlocation := cos (angle) * power * t
        currentYlocation := sin (angle) * power * t + 0.5 * gravity * (t) ** 2
        % draw the missile
        drawfilloval (round (currentXlocation), round (currentYlocation), 3, 3, black)
        if currentYlocation < 0 then
            quit
        end if
        View.Update
    end for
end loop


-----------------------------------
Tony
Fri Jan 11, 2008 1:07 pm

RE:Trajectory problems
-----------------------------------
are you sure that cos/sin operate on degrees, not radians?

-----------------------------------
Carey
Fri Jan 11, 2008 1:18 pm

RE:Trajectory problems
-----------------------------------
try cosd and sind instead. they use degrees, not radians
