The Daily Click ::. Forums ::. Klik Coding Help ::. X=Y Math expressions, need help
 

Post Reply  Post Oekaki 
 

Posted By Message

WillWill

Give me stuff

Registered
  24/07/2006
Points
  552
23rd December, 2006 at 13:08:17 -

Hey guys, Ima do this short since you wont reply anyway.

I wanna set my object's Y so it's relative to the X position.. Do you guys have any good examples on how to get tutorials? Anything about X and Y relatives, perhaps even Tan, but I dont think that's what I am looking for. I am looking for Delta X and Delta Y calculations. Sucks that I failed this in school, and now it turns out I need to learn it anyway!

 
http://www.morphboy.newgrounds.com/
^ Free tunes, as long as you contact me.

axel

Crazy?

Registered
  05/02/2005
Points
  4766

Game of the Week WinnerYou've Been Circy'd!
23rd December, 2006 at 14:33:10 -

Doesn't help us much when you don't tell us what it's for. What are you trying to do? A 360 degree movement/shooting engine or something?

Delta X and delta Y? Let's assume you're using a custom movement. The variables OldX and OldY are set to store the old X and Y coordinates, by updating before the player moves. DeltaX and DeltaY are also alterable variables.

* Always
- Set OldX to X("Active")
- Set OldY to Y("Active")

[events that move Active go here]

* Always
- Set DeltaX to X("Active") - OldX
- Set DeltaY to Y("Active") - OldY

Hope that helps you. I'm not really sure what you're asking for.

Oh, and if you're trying to move something in 360 degrees, here's how you do it:

* Always
- Active: Set value A to value A("Active") + Cos(ANGLE) * SPEED
- Active: Set value B to value B("Active") + Sin(ANGLE) * SPEED
- Active: Set X position to value A("Active")
- Active: Set Y position to value B("Active")

Image Edited by the Author.

 
n/a

WillWill

Give me stuff

Registered
  24/07/2006
Points
  552
23rd December, 2006 at 15:52:55 -

My dad explained it to me after a long (and furious) discussion.

I just want to be able to click somewhere on the field and make the active object go after the position without moving in a jerky way and moving straight for the destination. I have figured out the solution which is:

YPos = YPos + (Y Destination / X Destination)
XPos = XPos + (X Destination / Y Destination)

My mind can be quite glitchy sometimes.. I have to use this expression to calculate various and difficult things however, so don't take me for an idiot when I say that this is gonna be hard. My game follows a 4x4 grid system and when the object moves likes this I have to disable the grid system temporarily and allow it to move freely. But the obstacles are still in the 4x4 grid system, which means that I will have to compare what's closest to the XPos and YPos of the player object to what's nearest around him, to see if he is allowed to move further. Sounds kinda weird I know, but lets just say that I don't use any "If Object Collides" events, only pure X and Y.

Oh, and I need refreshing on how to turn values into decimals.. For example making a Global Value B as decimal, because I can't seem to do it.

Image Edited by the Author.

 
http://www.morphboy.newgrounds.com/
^ Free tunes, as long as you contact me.

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
23rd December, 2006 at 16:02:15 -

Values are stored only as integers.

 
My signature is never too big!!!

WillWill

Give me stuff

Registered
  24/07/2006
Points
  552
23rd December, 2006 at 16:04:37 -

Meh.. I think that formula was wrong.. I still need help. >_>

 
http://www.morphboy.newgrounds.com/
^ Free tunes, as long as you contact me.

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
23rd December, 2006 at 16:12:03 -

the change in X = (X2 - X1)
the change in Y = (Y2-Y1)

Depending on how fast you want it to move, it should be

Xcur = Xcur + (Change in X)/Speed of movement

repeat that until it gets to the new X co-ordinate.

The same goes for Y.

 
My signature is never too big!!!

WillWill

Give me stuff

Registered
  24/07/2006
Points
  552
23rd December, 2006 at 16:35:51 -

I tried that, and it seems like it doesn't really work completely. At the end it stops earlier than it should, and I fear it is because of the lack of decimals. I know decimals can be used..

 
http://www.morphboy.newgrounds.com/
^ Free tunes, as long as you contact me.

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
23rd December, 2006 at 16:39:17 -

They could probably be used if you used a string

String: Set alterable text to String$((Y2-Y1)/(X2-X1)) I think it's string$ anyway... might be Str$

Then in your calculations
Xcur = Xcur + Val(text in the string) -> use the expression editor to get the string, as im not sure of the expression for it, but remember to have (val) around it.

Same for Y

Image Edited by the Author.

 
My signature is never too big!!!

CodeCannon

of DringleTopia

Registered
  13/04/2006
Points
  208
23rd December, 2006 at 17:48:35 -

You can use and store floats in global/alterable values when you use "Set"; afaik "Add to" and "Subtract from" will convert the value to an integer, and you can't set the default value at design-time to a float either.

If you want to preserve the floating point of the co-ordinates of an object when moving it, you can have 2 alterable values in your object to use as X/Y buffers:

- Always
... Character: Set X Buffer to X Buffer("Character") + (X Delta * 1.0) / (Y Delta * 1.0)
... Character: Set X position to X("Character") + X Buffer("Character")
... Character: Set X Buffer to X Buffer("Character") - Int(X Buffer("Character"))

Remember to use Integer * 1.0 when you want to have float division using integer values (3/2 = 1; 3.0/2.0 = 1.5).

 
_
CodeCannon
http://www.dringletopia.da.ru/

WillWill

Give me stuff

Registered
  24/07/2006
Points
  552
23rd December, 2006 at 22:54:16 -

Yeah man, I tried doing a '0.0 +' in the beginning of the expressions instead, how foolish of me. The string method sounds acceptable too but it would be truly retarded if I can't have floats (doubles) in my code. God I hope I get a laptop for Christmas so I can program more.

I will try your method after the conspiracy is over (christmas).

Image Edited by the Author.

 
http://www.morphboy.newgrounds.com/
^ Free tunes, as long as you contact me.
   

Post Reply



 



Advertisement

Worth A Click