Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

whendric

15
Posts
5
Topics
4
Followers
14
Following
A member registered Jun 20, 2014 · View creator page →

Creator of

Recent community posts

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!

Vector2

Common Operations for Cartesian Vectors

Usage:

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.

Methods:

Vector2 has a number of common vector operations available to help you finish your game:

constructor

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:

Slope

v2.slope()

Returns the slope of the vector, calculayed as y/x

magnitude

v2.magnitude()

Returns the length of the vector

normalized

v2.normalized()

Returns a copy of this Vector2 with length 1

add

v2.add(_a, _b)

returns a new Vector2 that is the sum of vectors _a and _b

subtract

v2.subtract(_a, _b)

Returns a new Vector2 representing the difference between _a and _b

componentMultiply

v2.componentMulitply(_a, _b)

Returns _a scaled by _b on a per-component basis (_a.x * _b.x, _a.y * _b.y)

scale

v2.scale(_a, _s)

Returns _a scaled by _s, a real value scalar.

rnd

v2.rnd()

Returns a copy of this vector with each component rounded to the nearest integer.

flr

v2.flr()

Returns a copy of this vector with each component rounded down.

cling

v2.cling()

Returns a copy of this vector with each component rounded up.

dot

v2.dot(_a, _b)

Returns the dot product between _a and _b.

angle

v2.angle(_a, _b)

Returns the angle between _a and _b in degrees.

lerpV2

v2.rnd()

Returns a copy of this vector with each component rounded to the nearest integer.

reflect

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.

rotate

v2.angle(_r)

Returns this vector rotated by _r radians. To rotate by degrees, pass degtorad(degrees) into _r.

(1 edit)

Welcome to the Vector2 for GameMaker discussion!

Please be kind to others, and don't make me update the rules.

Rules:

  1. This is a dictatorship and I am Your Supreme Vector
  2. NO free speech
  3. Please be kind and helpful to others

Thank you for posting this :)

Hell yeah, Fox!


We really did a barrel roll out of that one!

As stated above, this is not a content creator tool but instead a relaxing game. It's probably better to spend your time in Blender than using this if you want to use it for game dev

It really has this interesting "Sim Tower" feel to it. Yoot Saito would be proud!

I clicked because screenshots!

Damn that little dog!

Really fun especially for followers of the Cult of Tim. GOTY!

Yeah thanks for checking out my game :)

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.

Don't crush the swordsman with your elevator!


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!

https://whendricso.itch.io/primita

Primita community · Created a new topic User Feedback

Hello! I'm looking for feedback on my game, how can I improve it? Are the controls intuitive?