Hi! If you're stuck on something, these guidelines can help us help you:
Please describe your question clearly
in context of your game
with pasted code
That's basically it. Happy coding!
Common Operations for Cartesian Vectors
Vector2 is implemented as a constructor in GML. To perform vector operations, we must first create a struct instance by calling this constructor. In this example, let’s create an orbiter:
//create event v2 = new Vector2(16,16)//offset vector va=v2//vector a, our output vector. Will be immediately overwritten //step event v2 = v2.rotate(degtorad(3))//rotate the offset vector by 3 degrees/step va = v2.add(v2,new Vector2(x,y))//add the offset to object world position //draw event draw_sprite(sprOrbiter,va.x,va.y)//draw sprite at offset
In this example, we create two Vector2’s, one to represent a 16x16 pixel offset which we will modify each frame (v2), and one to represent the absolute world position where we want to draw the sprite (va). Then in the Step event, we rotate v2 by 3 degrees and add this result to our object’s position to get the correct position to draw our orbiter sprite. Finally, in the Draw event, we draw the orbiter at it’s new position.
Vector2 is designed to work in a similar way to other game engines. When you use the new keyword or use any of the methods accessible through dot notation, a new struct is created in memory. If you instead modify the x & y components directly, the original vector is modified. This is because the methods inside Vector2 always return a new vector rather than modifying the existing one. This behavior is similar to that of other game engines, so many lessons from those engines apply here.
Vector2 has a number of common vector operations available to help you finish your game:
v2 = new Vector2(1,2)
Creates a new vector and populates it with an x and y component.
To perform any Vector2 operation, you must create at least one instance of it using the new keyword and assign it to a variable as seen above. Usage information below:
v2.slope()
Returns the slope of the vector, calculayed as y/x
v2.magnitude()
Returns the length of the vector
v2.normalized()
Returns a copy of this Vector2 with length 1
v2.add(_a, _b)
returns a new Vector2 that is the sum of vectors _a and _b
v2.subtract(_a, _b)
Returns a new Vector2 representing the difference between _a and _b
v2.componentMulitply(_a, _b)
Returns _a scaled by _b on a per-component basis (_a.x * _b.x, _a.y * _b.y)
v2.scale(_a, _s)
Returns _a scaled by _s, a real value scalar.
v2.rnd()
Returns a copy of this vector with each component rounded to the nearest integer.
v2.flr()
Returns a copy of this vector with each component rounded down.
v2.cling()
Returns a copy of this vector with each component rounded up.
v2.dot(_a, _b)
Returns the dot product between _a and _b.
v2.angle(_a, _b)
Returns the angle between _a and _b in degrees.
v2.rnd()
Returns a copy of this vector with each component rounded to the nearest integer.
v2.reflect(_a, _n)
Returns vector _a reflected from surface normal _n. _n is automatically normalized if it’s length isn’t already equal to one.
v2.angle(_r)
Returns this vector rotated by _r radians. To rotate by degrees, pass degtorad(degrees) into _r.
Thanks for your feedback! I will definitely take these lessons into account.
I agree, I need some sort of tutorial. The tank button does buy tanks but you have to scroll the view (with W and S) to see them. You can then paint selection and give them orders. They spawn inside your base which is behind the shield. This is a problem others have mentioned to me before.
Primita is an action/arcade tactical RTS prototype. I am looking for feedback on how I can make it better. It's a short game, only one level right now, and I intend to keep it free. It was developed using my Unity game framework called MultiGame which you can get for free while it's still in alpha.
Please let me know what you think and any suggestions you might have, I would love to get some feedback :)
Thanks!