How do I emulate vector2?

0 favourites
  • 4 posts
  • Hey wonderful people!

    So, I've been trying to set up a basing steering behaviour in Construct 3. The issue that I'm having is that Construct does not seem to have the ability to work with vectors.

    How can I use the tools that Construct gives me, and most likely some math, to replicate the results of using vectors.

    For instance using vectors and some variables for max speed and acceleration I could create a "seek" behaviour like this:

    player = X,Y, 0 target = X,Y, 100 player.maxSpeed = 100 player.steer = 5 1. desiredVelocity (a vector) = normalize(target X,Y - player X,Y) * player.maxSpeed 2. steeringForce (a vector) = desiredVelocity - player's CurrentVelocity (vector), limit (the magnitude of) steeringForce to player.steerForce 3. newVelocity = player's currentVelocity + steeringForce, limit newVelocity to player.maxSpeed

    This would create a simpel seeking behaviour where the player would smoothly follow the target.

    How can I use the tools that Construct provides me to achieve the same sort of thing?

    R0J0hound Your posts have helped me many times in the past. Do you have any sage advice on this?

    Thanks!

  • I noticed that the code block made things very hard to read so here's the pseudo code again:

    player = X,Y, 0

    target = X,Y, 100

    player.maxSpeed = 100

    player.steer = 5

    1. desiredVelocity (a vector) = normalize(target X,Y - player X,Y) * player.maxSpeed

    2. steeringForce (a vector) = desiredVelocity - player's CurrentVelocity (vector), limit (the magnitude of) steeringForce to player.steerForce

    3. newVelocity = player's currentVelocity + steeringForce, limit newVelocity to player.maxSpeed

  • You just have to use two numbers to represent a vector. And do math per component.

    So instead of something like c=a+b you’d do:

    cx=ax+bx

    cy=ay+cy

    And instead of normalize(a) it would be:

    mag=sqrt(ax*ax+ay*ay)

    ax = ax/mag

    ay = ay/mag

    And stuff like that. So you may need more variables to to temporarily store the steps of the calculations.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thank you! That's very helpful.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)