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!
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")
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.
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..
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.
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).
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).