ID:272880
May 11 2009, 8:51 am
|
|
I am making a technique in my game that repulses a person away from the user, how would i code that? I know it is a simple peice of code, i have done it before, but i cant remember how...
|
May 11 2009, 9:39 am
|
|
In response to GhostAnime
|
|
ok, im not 100% sure if thats what im looking for.. i mean all i want to do is push them away from the user. Say im a mob, and regaurdless of the targets direction, pushes him back like 3 squares. so not just make him moves opposite his direction, just away from the user
|
In response to Roxas_KeyBlade
|
|
for(var/steps in 1 to 3) |
In response to Kaiochao
|
|
In response to GhostAnime
|
|
You can preserve the original dir without extra work by expanding the step() call into a Move() call instead, and using its 2nd argument.
X.Move(get_step(X,turn(X.dir,180)),X.dir) EDIT: Completed code. |
In response to Kaioken
|
|
In response to Schnitzelnagler
|
|
Yes, I forgot the get_step() part; that's how it is with multiple nested proc calls. Sometimes after you finish one you think you're done. xD
|
In response to Kaioken
|
|
Why not do something like;
walk_away(M,src,1,0) |
In response to VolksBlade
|
|
I'd say that depends on how pushing into dense objects is supposed to be handled by the original poster.
|
In response to Schnitzelnagler
|
|
Sorry, I meant get_dir().
|
In response to Kaiochao
|
|
In that case, caching the result outside the loop might be a smart move, in order to avoid calling it thrice, since the result shouldn't change ;)
You could even break the loop when step returns 0, avoiding unnecessary calls (especially since the proc sleeps). Kaiochao wrote with slight edit: var/d = get_dir(src,M) Edit: Or, the Kaioken way, using Move: var/d = get_dir(src,M) Note, it might be better to use get_dir, than turn, since there is no warranty that the mob you want to push away from the user was facing her before. |