Abs with Sin to make Enemy go forward and back?
Blitz3D Forums/Blitz3D Beginners Area/Abs with Sin to make Enemy go forward and back?
| ||
Hiya all, Correct me if I am wrong...the command called Abs which does the trick with sin or cos to make the enemys go forward and back... |
| ||
??? Abs is nothing to do with Sin or Cos. You might be looking for Atan2 but I don't know since you haven't said exactly what you're trying to do. |
| ||
ABS will take make any number positive, ie ABS(-1) = 1 No idea what you're talking about with the "does the trick with sin or cos to make the enemys go forward and back" However, for you run a counter from 0 to 359 ie count = (count + 1) mod 360 x = sin(count) * [distance to move] because sin ranges from -1 to 1 you will make things move left and right. |
| ||
What I am trying to do is make the enemys go forward and backward just using one commands.... so you say ATAN2....how do I do that in the code to make the enemys forward and backward? |
| ||
Explanation in my previous post.c=0 Repeat Cls For x=-10 To 10 Text 200+(x*10),(Sin(c+(x*10))*50)+100,"X",True,True Next c = (c+1) Mod 360 Flip Until KeyHit(1) |
| ||
That was interesting sin wave you got there. :) it is Platform game I am making. For now I using just two IF command to make the enemys go forward and backward but I am sure there is just one command to make the enemys go forward and backward. |
| ||
Hello. Perhaps this is what you mean? I'm not at work so I can't be sure what's happening. Obviously, it's all my own original code too ;o) Perhaps what HotShot is trying to acheive is drawing a circle but only changing the x or the y element - that does have the affect of moving back and forth. (BTW, I'm assuming that's what the amended code is doing) Code Removed Goodbye. |
| ||
Hello. Ok, it's BlitzMax but easy enough to convert Strict Graphics 800,600,0 Local i:Int While Not KeyDown(KEY_ESCAPE) Cls i:+1 i:Mod 360 If (i>180) Then SetColor 255,255,0 Else SetColor 0,0,255 DrawOval 100*(Sin(i+90))+400,300,8,8 Flip Wend End Is that what you mean? Goodbye. |
| ||
yep that right Soggy :) wicked |
| ||
the alternative what you most likely are looking for is signum (sgn) which returns -1, 0, 1 depending on the input is < 0, 0, > 0 |