The Daily Click ::. Forums ::. Klik Coding Help ::. issue with calculation
 

Post Reply  Post Oekaki 
 

Posted By Message

Chloe Sagal

under the influence of FUN

Registered
  19/02/2009
Points
  607

Orange
22nd April, 2009 at 05:00:50 -

i feel really dumb. for some reason this code worked perfect for my game, but now it just up and decided it wont work anymore. it seems no matter what i do, it always says syntax error. this is how the calculation was when it was working. i notice that there seems to be an extra parenthasees before the *LoopIndex("aim"), but its wierd because it used to work.

X( "Player" )+Cos((YMouse-Y( "Player" )), (XMouse-X( "Player" ))))*LoopIndex("aim")
Y( "Player" )+Sin((YMouse-Y( "Player" )), (XMouse-X( "Player" ))))*LoopIndex("aim")

 
Patreon: http://www.patreon.com/chloesagal
Twitter: https://twitter.com/ChloeSagal

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
22nd April, 2009 at 05:54:58 -

you didnt edit ANYTHING in those before it stopped working?

did you try removing the parentheses?

 
n/a

Chloe Sagal

under the influence of FUN

Registered
  19/02/2009
Points
  607

Orange
22nd April, 2009 at 06:39:46 -

yeah, like i said, it was weird.

the only combination of paranthasees that work is

X( "Player" )+Cos(YMouse-Y( "Player" )), (XMouse-X( "Player" ))*LoopIndex("aim")

for both and that totally changes the meaning of the equation, resulting in the doodad to always be centered about the player. horrifying really.

 
Patreon: http://www.patreon.com/chloesagal
Twitter: https://twitter.com/ChloeSagal

nim



Registered
  17/05/2002
Points
  7234
22nd April, 2009 at 06:43:57 -

Yup, those are extra parentheses. Did you delete an object and its info was removed from the expressions, maybe?

 
//

Chloe Sagal

under the influence of FUN

Registered
  19/02/2009
Points
  607

Orange
22nd April, 2009 at 07:36:15 -

nope. just decided that it wanted to go on strike for some reason.

 
Patreon: http://www.patreon.com/chloesagal
Twitter: https://twitter.com/ChloeSagal

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49667

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
22nd April, 2009 at 14:32:59 -

MMF2 for some reason doesn't like your comma inside of the parenthesis. Try calculating that separately putting it into a variable then plugging the variable into the cosine.

Like:
On Loop "aim"
-Set myVar to YMouse-Y( "Player" ), XMouse-X( "Player" )
-Set "Player" X Position to X( "Player" )+Cos("myVar")*LoopIndex("aim")
-Set "Player" Y Position to Y( "Player" )+Sin("myVar")*LoopIndex("aim")

"myVar" being a alterable variable or a counter or something.

Good Luck!


 
n/a

Chloe Sagal

under the influence of FUN

Registered
  19/02/2009
Points
  607

Orange
22nd April, 2009 at 18:34:39 -

nope, still freaks out at the comma. thanks for narrowing it down tho!

EDIT: is there an extention to get the same calculation? either for the full calculation or the separate variable plugged into the sin and cosine?

Edited by Chloe Sagal

 
Patreon: http://www.patreon.com/chloesagal
Twitter: https://twitter.com/ChloeSagal

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
22nd April, 2009 at 20:29:26 -

You originally made the expression in the standard build of MMF2, which supports the ATan2 funtion (which you used).

You then loaded it using the HWA (or some other) build, which does NOT support ATan2. As a result, MMF filters out the "ATan2()", leaving an incomplete expression (including commas) which MMF can't interpret.

If you want to continue using this build, you will have to use an extension, such as the Advanced Direction object.

I could be talking out my arse of course...

Edited by Sketchy

 
n/a

Chloe Sagal

under the influence of FUN

Registered
  19/02/2009
Points
  607

Orange
22nd April, 2009 at 20:47:52 -

thats exactly what i figured, although for some strange reason, i never loaded the file into HWA (just copied the code over) and it wont work in the standard version aswell. do you know what function in the extention i should use?

 
Patreon: http://www.patreon.com/chloesagal
Twitter: https://twitter.com/ChloeSagal

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49667

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
22nd April, 2009 at 21:44:51 -

Hmm, thats weird, it worked for me.

I must have the build you originally used.
I don't know.

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
22nd April, 2009 at 22:53:05 -

If you use the Advanced Direction extension, I think the function is:
Distance and direction between two points -> Float Values -> Direction between two points

The Advanced Math extension has a similar function under "Pre-coded formulas".
There are probably other extensions you could use aswell, but I don't know.
There's even a way to do it without extensions, but it uses a *hugely* complicated formula that Nifflas came up with.

 
n/a

MBK



Registered
  07/06/2007
Points
  1578

VIP Member
23rd April, 2009 at 04:50:09 -

What's Nifflas' formula? ... that'd be great to know.


 
Click Me! http://www.create-games.com/project.asp?view=main&id=1444

http://www.mediafire.com/download.php?aoo1dnnlq5i

Blood of the Ancient One, Seen only as Shadow, Faster than Lightning, Fierce as the Greatest Dragon, Nearly Invisible, Floating in a Dream, Entered through the Demon Door, Destroyer of Evil in a Realm with a Red Sky Scarred, Who could I be ?

Chloe Sagal

under the influence of FUN

Registered
  19/02/2009
Points
  607

Orange
23rd April, 2009 at 05:28:04 -

i was thinking that same thing.

the direction from player was the right formula, thanks alot sketchy!

the only other issue it has is that its backwards, rather than follow the actual mouse, it mirrors it, ill try messing with signs but in case i dont get it, do you have a solution for that?

ed: yeah, it was just the signs needed changing. both were X/Y - Cos/Sin, when it needs to be X + Cos and Y + Sin. there is also an issue with the camera, but for some reason the code for it decided to run and hide. it still functions like its there but its not there, and i dont have anything unselected. weird. ill try to find the code im using and post it.

edx2:

set angle to Sqr((((X( "camera" )+((XMouse-X( "camera" ))/15.0))-X( "player" )) pow 2)+(((Y( "camera" )+((YMouse-Y( "camera" ))/15.0))-Y( "player" )) pow 2))

set direction to Y( "player" )-(Y( "camera" )+((YMouse-Y( "camera" ))/15.0)), (X( "camera" )+((XMouse-X( "camera" ))/15.0))-X( "player" ))

set cam x to X( "player" )+(Cos(directionFromPlayer( "camera" ))*Min(angleFromPlayer( "camera" ), 50))

set cam y to Y( "player" )-(Sin(directionFromPlayer( "camera" ))*Min(angleFromPlayer( "camera" ), 50))

that one gets all screwy, and id use the advance direction but again, its the same problem, i dont know which ones to use, obviously for the direction i use direction from player, but angle i somethin else.

edx3: lol, okay so i plugged in the direction from player for the direction variable, then flipped the signs for the cosx and siny and it seems to work fine, but its a little faster than im used to, and the angle variable might be the issue, do you know which extention and formula i could use as a substitute?

Edited by Chloe Sagal

 
Patreon: http://www.patreon.com/chloesagal
Twitter: https://twitter.com/ChloeSagal

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
23rd April, 2009 at 12:33:11 -

Nifflas' formula:
Angle = Abs(360*Min(Max(A.y - B.y)+1, 0), 1)-(ASin((B.x - A.x)/Sqr(A.x - B.x) pow 2 + (A.y - B.y) pow 2))+270))

Or, for a version that you can copy and paste straight into MMF (just rename Point A and Point B);

Angle = Abs(360*Min(Max(Y( "Point A" )-Y( "Point B" )+1, 0), 1)-(ASin((X( "Point B" )-X( "Point A" ))/Sqr((X( "Point A" )-X( "Point B" )) pow 2+((Y( "Point A" ))-Y( "Point B" )) pow 2))+270))

Like I said, it's very complicated. You can find this and other useful formulas are in my article "Useful Formulas".


set cam x to X( "player" )+(Cos(directionFromPlayer( "camera" ))*Min(angleFromPlayer( "camera" ), 50))
set cam y to Y( "player" )-(Sin(directionFromPlayer( "camera" ))*Min(angleFromPlayer( "camera" ), 50))

Shouldn't that be the distance from the player, rather than the angle? And also angle rather than the direction? (I thought directions were just 0-31?)
Actually, if you want to exactly replicate your original expression (the one that stopped working), shouldn't it be:

set cam x to X( "player" )+(Cos(angleFromPlayer( "camera" ))*LoopIndex("aim"))
set cam y to Y( "player" )-(Sin(angleFromPlayer( "camera" ))*LoopIndex("aim"))
?

 
n/a

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49667

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
23rd April, 2009 at 15:26:43 -

I have that article bookmarked!
I refer back to it when I need it.

 
n/a

Chloe Sagal

under the influence of FUN

Registered
  19/02/2009
Points
  607

Orange
23rd April, 2009 at 16:24:26 -


Originally Posted by Sketchy
Nifflas' formula:
Angle = Abs(360*Min(Max(A.y - B.y)+1, 0), 1)-(ASin((B.x - A.x)/Sqr(A.x - B.x) pow 2 + (A.y - B.y) pow 2))+270))

Or, for a version that you can copy and paste straight into MMF (just rename Point A and Point B);

Angle = Abs(360*Min(Max(Y( "Point A" )-Y( "Point B" )+1, 0), 1)-(ASin((X( "Point B" )-X( "Point A" ))/Sqr((X( "Point A" )-X( "Point B" )) pow 2+((Y( "Point A" ))-Y( "Point B" )) pow 2))+270))

Like I said, it's very complicated. You can find this and other useful formulas are in my article "Useful Formulas".


set cam x to X( "player" )+(Cos(directionFromPlayer( "camera" ))*Min(angleFromPlayer( "camera" ), 50))
set cam y to Y( "player" )-(Sin(directionFromPlayer( "camera" ))*Min(angleFromPlayer( "camera" ), 50))

Shouldn't that be the distance from the player, rather than the angle? And also angle rather than the direction? (I thought directions were just 0-31?)
Actually, if you want to exactly replicate your original expression (the one that stopped working), shouldn't it be:

set cam x to X( "player" )+(Cos(angleFromPlayer( "camera" ))*LoopIndex("aim"))
set cam y to Y( "player" )-(Sin(angleFromPlayer( "camera" ))*LoopIndex("aim"))
?



the only problem with doing that is id have to add another loop, because the loop index contains the variables for the aimer thing. id add another loop but according to the internet, they eat up tons of memory. the only reason i have the aimer thing in a loop is because i found a nifty little tutorial that made it so the thing follows walls (instead of going through them).

ill try throwing in the distance from player in that angle calculation and see if it works any better. thanks alot for your help!

edeat: nah, that didnt work, it just sucked the camera object to the player like it was stuck in some kind of warp holemajig. which was cool but that wasnt the intended effect. ill look over your article and see if theres any nifty tidbits i can find.

Edited by Chloe Sagal

 
Patreon: http://www.patreon.com/chloesagal
Twitter: https://twitter.com/ChloeSagal
   

Post Reply



 



Advertisement

Worth A Click