Hi there,
Does anyone have any simple examples they would like to share on how to use the mathematical functions (sin, cos etc). I have used the help options on all of them but would learn them faster if I could see them in action - the simpler the better.
Would really appreciate some help!
Offline
Well, for sin and cos, my Tank Game uses it to go to the correct position. The abs can be used for determining the distance to something (abs of your X to abs of their X). The possibilities are endless with them

Offline
17church wrote:
Any chance of a quick example?
Haha, maths was not my best subject, but I do learn quickly once shown how it could be used!
Hmmm, alright, lemme see… Well, here is the tank game:
<change x by( <sin( Xposition of Body
<change y by( <cos( Yposition of Body

Offline
17church wrote:
Any chance of a quick example?
Haha, maths was not my best subject, but I do learn quickly once shown how it could be used!
Here's an example using the Scratch coordinate system (zero is up): Let's say you would like to compute the position of a point (let's call it Point B) that lies in direction 25 and at a distance of 10 steps from your current point (let's call it point A). The X and Y coordinates can be calculated using:
Point_B_X = Point_A_X + Sin(25) * 10
Point_B_Y = Point_A_Y + Cos(25) * 10
Where Point_A_X is the X position of Point A and so on. Hope that helps!
Offline
Cool, will have a play.
One more thing: I am working on a team basketball game at the moment, quite hard, but I'm making good progress. I have the user controlling one team, using space bar to pass the ball to another player until it gets to the hoop.
Two questions:
1) Can I get a player (sprite) to pass the ball to the nearest player in his team? I just cant seem to get this one, so at the moment I have them passing in sequence, but that gets boring. I have made the ball follow the mouse pointer which solves that problem but would prefer it to pass to nearest sprite on click.
2) The other team is set to pass in sequence automatically, which I am happy with. I would like there to somehow be intercepts, so I I pass the ball to my player, but an opposition player is in the way then they grab the ball. But it seems like once the command of passing to my own player is in motion it doesnt stop, even if I have told it to stop (if touching...)
Confusing?
Offline
1) you can either A: set a variable, and assign each member (if they don't have the ball. Again, using variables to see who does) a number, and if the variable equals their number, they get the ball. Or, you can check the distance to each teamate with the <distance to[
blocks to see who is closets. The same for the computer players intercepting. When you pass, set a variable to 1, and if the distance to the ball is less than a certain number and passing equals 1, the computer player wil intercept, but remember to reset the variable when the ball is caught

Offline
17church wrote:
Cool, will have a play.
One more thing: I am working on a team basketball game at the moment, quite hard, but I'm making good progress. I have the user controlling one team, using space bar to pass the ball to another player until it gets to the hoop.
Two questions:
1) Can I get a player (sprite) to pass the ball to the nearest player in his team? I just cant seem to get this one, so at the moment I have them passing in sequence, but that gets boring. I have made the ball follow the mouse pointer which solves that problem but would prefer it to pass to nearest sprite on click.
2) The other team is set to pass in sequence automatically, which I am happy with. I would like there to somehow be intercepts, so I I pass the ball to my player, but an opposition player is in the way then they grab the ball. But it seems like once the command of passing to my own player is in motion it doesnt stop, even if I have told it to stop (if touching...)
Confusing?
Probably should have started a new thread for this since it pretty much is a new topic...whatever.
Anyway, Blue is correct that the "Distance To" sensor block will be useful in finding the closest player. You will also find this much easier to do in the next release since you can build a list of distances to players and sort the list to find the closest player. In the current version, I might instead use a sensing sprite with the Ghost effect set to 100 so it is invisible. Have the sensing sprite locate on the player passing the ball and have it increase size repeatedly until it contacts another player on your team - that will be the closest player. It might be a slow technique but it will be fairly easy to code.
Another thing is if you are using Glide blocks to pass the ball, you are not going to be able to intercept them...they go until they get to their final destination. Instead, you will probably need to use Move blocks in a Repeat Until loop with the exit condition of the loop set up for when the ball touches an enemy player. Hope that helps. Sounds like a fun game!
Offline