R0J0hound's Recent Forum Activity

  • If only two instances were colliding then an overlap condition would work. You’d get either instance with pick nth instance with 0 or 1. That won’t work if more overlap since we want to loop over all the colliding pairs.

    Roughly to loop over the pairs you’d do this:

    var i=0
    var j=0
    For “i” from 0 to family.count-2
    For “j” from i+1to family.count-1
    — set i to loopindex("i")
    — set j to loopindex("j")
    — compare abs(family(i).x-family(j).x)<32
    — — do something

    The collision expression is basic here. It don’t have a better one off the top of my head atm. But the idea is you use an expression to see if the two objects collide instead of the overlap condition. Then to modify the instances you pick the nth instance using i and j.

  • There are a few ways to do it a bit different with some trade offs.

    I tend to use one object with one family containing that object. The advantage is you can access instance variables from both. The con is you have only one object type but I find it fine. You can use different animation frames.

    Another option is multiple object types and one family. We can then utilize iids to reference two different instances at once. Then to modify them you can use pick nth instance. The con is you couldn’t use the overlapping events, so you’d have to roll your own which isn’t too terrible for circles and boxes. Although the loop is a bit more nuanced.

    One nuisance of using two families is having instance variables shared between the two. I guess the custom movement behavior is one way around that, but I’ve found that behavior not very useful since applying velocity is fairly simple to apply velocity to make movement.

    But if staying with two families you could have each family have similarly named instance variables and copy between the two. Or maybe use a function to access them instead.

    As is, you can remove the for each in the bottom two events and it’ll still work, since the actions only reference themselves.

  • What kind of shape did you have in mind?

    Squares, circles and convex polygons are simpler.

    The logic would be if not inside the shape move the object to the closest point on the edge of the shape.

    For polygons the prices needed are:

    Finding of a point is inside of a polygon, distance to a point, and distance to a line segment.

    For irregular polygons with concave parts I think the above wouldn’t work super well.

    For that I think you could consider a line from its position to its new position, and stop and slide on the first edge it intersects.

    If you had a particular shape in mind there may be simpler ways to do it.

  • Boxes are a bit more involved.

    For a circle you use the distance between the points and the center of the circle. For a box you use the distance from the closest point on the edge of the box.

    For a non rotated box you could get that point with:

    X = clamp(p.x, box.bbleft, box.bbright)

    Y = clamp(p.y, box.bbtop, box.bbbottom)

    At least that’s a start. That gives points inside the box.

    I’ve run out of time again. Time management for me is very poor lately.

  • Ah, well moving 15 pixels instead of 1 would work but I think you missed what the original solution was.

    When a wall is hit it turns it 180 degrees.

    Then it does a loop to see if it’s overlapping a wall and move 1 pixel at a time till it’s out of the wall. That way it will move as many pixels as necessary to get out of the wall.

  • No regex was used here. In c you’d have more options of ways to do it. You could do it the same, just the string functions would be named differently. C also has that conditional operator ?:

    Probably in c you’d use an array instead of the token at.

    This would be basically the same in c. I didn’t do the part to extract the name.

    char right(char* s)
    { 
     int i=0;
     while(s[i]) i++;
     return s[i-1];
    }
    char* getBest(char* a, char* b, char* c)
    {
     char* best = right(a)>right(b)?a:b;
     best = right(best)>right(c)?best:c;
     return best;
    }
    
    int main()
    {
    char* apple="apple3", pear="pear4", mango="mango1";
    char* best = getBest(apple, pear, mango);
    
    int prices[] = {50, 100, 200, 800};
    int cost = prices[right(best)-'0'];
    }
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The solution sounds complicated.

    This would set best to the var with the highest digit.

    best = right(apple,1)>right(pear,1)?apple:pear

    best = right(best,1)>right(mango,1)?best:mango

    Then we can split the name and number.

    name = left(best, len(best)-1)

    num = int(right(best,1))

    And you can lookup the prices with:

    If name=“apple”

    — price = tolenat("50,100,150,200", num-1, ",")

    And similarly for pear and mango.

    Anyways, cheers

  • Does the number have to be at the right? If you put it at the left you can do this. Pretty sure the text gets converted to a number to compare automatically.

    Best = (apple>pear)?apple:pear

    Best = (best>mango)?best:mango

  • That’s not implemented yet. Will be eventually when I get to it.

  • Lots of 3D stuff in my posts.

    construct.net/en/forum/search

    In the don’t stare topic i have and example of rotation and perspective scaling math.

    Also there’s a new plugin that I’m working on to do 3D.

    construct.net/en/forum/extending-construct-2/work-in-progress-addons-30/triangle3d-plugin-160497

    Then there’s this that draws in 3D with the paster object. I don’t think I posted it here. Not sure though.

    dropbox.com/s/gsga6cs5cj6byp8/3dMath_2.0.capx

  • Updated 5/15/21

    More useful for a 3d game. Still working out how to best handle the camera, but you can draw stuff with 3d rotations so that's cool.

    cheers

  • Gravity is just applying a force toward the planet. Not just any force, it should depend on the distance from the planet to be closer to real physics.

    Something like this:

    force 10000/distance(self.X,self.Y,earth.X,earth.Y)^2 toward (planet.x, planet.y)

    For an orbit you just set an initial velocity. Using an impulse to do that works too. Just make it perpendicular to the direction to the planet.

    Something like this:

    impulse: 50/distance(self.X,self.Y,earth.X,earth.Y) at angle(self.X,self.Y,earth.X,earth.Y)+90

    The 10000 and 50 were purely arbitrary. I just tuned them till i got something reasonable. the 10000 defined how strong the gravity was, and the 50 gave me orbits that lasted a while.

    If you're curious there are perfect values that can be calculated in real life, but the units with the physics behavior are wonky so I just fudged it to get something reasonable.