Computer Science Canada Trigonometry Help, Hockey Game, Shooting |
Author: | @DRI@N [ Wed May 26, 2004 9:08 pm ] | ||
Post subject: | Trigonometry Help, Hockey Game, Shooting | ||
Can anyone spot what's wrong here because I can't see it. YOu press shift to shoot. Works alright from pretty close but if u shoot from far only the xchange increases. What I did was find the angle using Tan(opp/adj) and then multiplied my angle by the movement(2) and divided it by 90 to get x velocity. For Y i did the same but did (90-angle)...please help...
|
Author: | @DRI@N [ Wed May 26, 2004 9:16 pm ] |
Post subject: | |
I just noticed too....it shoots faster from the right side of the screen and.. sometimes doesn't bounce off the walls..can anyone tell me what the fuck is going on???? |
Author: | Tony [ Wed May 26, 2004 10:01 pm ] | ||
Post subject: | |||
no no no lets go back to our grade 10 trig class. you got the angle... good
where totalVelocity is the absolute speed of the puck. It could be a static value or depend on player's stength or w/e variable for more depth |
Author: | guruguru [ Wed May 26, 2004 10:17 pm ] |
Post subject: | |
I want to argue with you Tony... I believe his method is right... but you're the expert so I'm gonna drop it . |
Author: | Tony [ Wed May 26, 2004 10:22 pm ] |
Post subject: | |
no, plz argue with me, I'd like to see what a 15 year old has to teach me about trig functions |
Author: | guruguru [ Thu May 27, 2004 4:04 pm ] | ||
Post subject: | |||
EDIT EDIT EDIT: I am wrong!!! I was thinking of totalVelocity as the sum of the x and y velocities!!! Tony brought that to my attention in the other (identical :p) post. Tony wins again . You can read below for interest but dun think about implementing it because its not right lol... Gladly! I like arguing math (even if I (am) have a chance being wrong). Ok. He has the slope. And he gets the angle. We gots that . But your way does not work. Lets say that the angle is 45, and totalVelocity 10. Hence, both the x and y velocities should be equal and have a sum of totalVelocity. Well, lets see if the methods work..
Please counter-argue!!! This is getting fun fun fun !!! Note: I switched the x and y velcotiy formulas in @dri@ans (and mine indirectly), because they were messed up and I wasn't thinking fully right when I made them. |
Author: | @DRI@N [ Thu May 27, 2004 4:22 pm ] |
Post subject: | |
So the "movement" varialbe I had shood be 10? and then all i need to change is the (90-x) part? sorry I'm kinda confused because I never used "Total Velocity" in my program |
Author: | guruguru [ Thu May 27, 2004 4:25 pm ] |
Post subject: | |
No no no... you must use Tony's version. Quote: velocityX := totalVelocity * cosd(angle) velocityY := totalVelocity * sind(angle) totalVelocity is movement in your program. BTW Tony: We take trig in grade 9. |
Author: | @DRI@N [ Thu May 27, 2004 4:30 pm ] |
Post subject: | |
Something is still wrong I just tried it...its slower from some places and always shoots 45 degrees, NOT at the net |
Author: | @DRI@N [ Thu May 27, 2004 4:37 pm ] | ||||
Post subject: | |||||
Here's what I did...for the functions. It works from some places..but from the right side of the screen the shots are backwards. When it hits the boards it should slow down again to xchange=1 ychange=1 but instead it flies off at the same speed as the shot.
As well....I have my if statements for Collision to know when he gets the puck, and..he cant shoot because of that because the puck is within the collision zone when im trying to shoot. How do I overcome these 3 problems...
|
Author: | guruguru [ Thu May 27, 2004 4:47 pm ] |
Post subject: | |
Functions look ok... you should have the variables declared globally, not in the functions. And you should have one function for both values. Simple make a test for the direction and then make negative/positive the x/y velcoityes based on that test. It probally shoots at 45 degrees because you have local and global puck values. Make them just global. What are the x and y values? The player? or puck? And what is the collission zone? I'm confused about what you are asking. |
Author: | @DRI@N [ Thu May 27, 2004 4:56 pm ] |
Post subject: | |
Forget the shooting I think I fixed it...Ok collisions...I have if statements so when the puck goes withing this "invisible" rectangle(basically right around the player) to move to his stick. Otherwise it will just go by him and I want him to be able to have the puck right? Well when I want to take a shot...the puck is on his stick....and it cannot exit the "invisible" box because it is always being told to return it to his stick |
Author: | guruguru [ Thu May 27, 2004 5:11 pm ] |
Post subject: | |
Mkae a boolean variable onStick. When onStick is false, the ball goes to the stick. And then onStick := true when it reaches the stick. When it is true, then the 'go on stick' procedure is not called and just the shoot procedure is called. Then onStick := false after shot is made. |
Author: | @DRI@N [ Thu May 27, 2004 5:16 pm ] |
Post subject: | |
K ill try that in a minute...the damn shooting from the right side just goes down and through the walls too |
Author: | guruguru [ Thu May 27, 2004 5:36 pm ] |
Post subject: | |
Make sure the collision detection has no little faults. Make sure you < and > are not switched, and that you are testing the right coordinates. As well, like I said before, check the directin of the current velocity and adjust it so that it goes up/dow/left/right. |
Author: | @DRI@N [ Thu May 27, 2004 5:42 pm ] |
Post subject: | |
How do I check it..If its left of centre then go right If its right of centre go left If in the middle just go straight |
Author: | guruguru [ Thu May 27, 2004 5:56 pm ] |
Post subject: | |
It shoould be based on last velocity and where it was hit. If it was going down and was hit up, or vice versa- velocityY := -velocityY. If it was going left and was hit up, or vice versa- velocityX := -veclocityX. Just check the direction of the x and y puck changes. Adjust those. If they are positive and need to be negative, make them negative. |
Author: | @DRI@N [ Fri May 28, 2004 8:46 pm ] |
Post subject: | |
Collision thing wont work..the way you put, I have to set collision to false. Collision is a boolean function not a variable...so I cant assign a value to it |
Author: | guruguru [ Fri May 28, 2004 9:49 pm ] |
Post subject: | |
Then you can make a new boolean variable. Then your collision function can change the new variable. Or it can just return a local variable in itself that determines if the puck should be drawn toward the stick or not. |
Author: | @DRI@N [ Sat May 29, 2004 9:18 pm ] |
Post subject: | |
I think I already tried that.....I was thinking to move the puck to the edge of the collision box and then shooting it as opposed to the whole collision variable thing.. |
Author: | guruguru [ Sun May 30, 2004 12:14 am ] |
Post subject: | |
Try what you might, both ways should work. It may be simpler your way I dont know. |
Author: | @DRI@N [ Sun May 30, 2004 7:03 pm ] |
Post subject: | |
Or I could just say if the slope is 1 then, and only then go to the stick otherwise just shoot or if ur blocking a shot...bounce off |