R0J0hound's Recent Forum Activity

  • In my experience "Bounce Off Solids" works well only when bouncing off of stationary objects.

    For example this uses "Bounce Off Solids" for everything.

    https://dl.dropboxusercontent.com/u/542 ... owd_1.capx

    Notice unsightly teleportation when objects get in close quarters.

    So one Idea that eliminates the teleporting is to have the enemies not have the solid behavior and resolve their collisions as they move with events. Basically it involves checking the distances of every enemy with all the others. If the enemies are too close we can calculate exactly how much they are overlapping and then can move one enemy half the overlap one way and the other enemy half the distance the other way.

    https://dl.dropboxusercontent.com/u/542 ... owd_2.capx

    One thing that is not addressed is changing the enemy's speed. They will appear to stop until the path is free and they will jet back at their original speed.

    In this final example I addressed the lack of bouncing. To do it I needed to get and set velocity x and y so I opted to remove the bullet behavior and do the movement with events.

    https://dl.dropboxusercontent.com/u/542 ... owd_3.capx

    It works well, but there is no collision response with the walls.

    You could make example 2 work with the bouncing in example 3 by converting the bullet behavior's speed and angleOfMotion to vx and vy with:

    vx=speed*cos(angleOfMotion)

    vy=speed*sin(angleOfMotion)

    doing the calculations and then converting back with:

    speed=distance(0,0,vx,vy)

    angleOfMotion=angle(0,0,vx,vy)

    Another idea would be just to use the physics behavior for the whole bit.

  • Opps... I see I had the subtraction reversed. :p Glad you got it working.

    cheers

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You'll have to use this plugin to get the date:

    http://c2rexplugins.weebly.com/rex_date.html

    on the start date save the UnixTimestamp (seconds since Jan 1, 1970) to webstorage for later, we'll call this start_time.

    Then any following times you want to see how many days have passed you retrieve the saved time from webstorage and subtract the current UnixTimestamp. That will give you the number of seconds from one date to another. Divide by 60 to get minutes, 60 again to get hours, and finally also by 24 to get days.

    days = (start_time - UnixTimestamp)/60/60/24

  • The closest thing to that would be to use the third party Canvas plugin. It has a rgbaAt expression but it only works to get the color on the canvas object's texture. It also has actions to draw other objects onto this texture which is useful.

    The overall method would be to draw everything on screen to a screen sized canvas object, and after that get the color with rgbaAt.

  • Short version:

    1.The 2500 is from the conversion factor (50) from box2d units to pixels.

    2. Your equation to calculate won't work for all shapes. Instead of just mass you need to calculate the Moment of Inertia for that particular object. After that the only magic number is 0.02 or (1/50) which is the conversion factor from pixels to box2d units.

    3. [quote:2iwgq6s7]AngularVelocity = Velocity / Diameter (pi)

    should be:

    AngularVelocity = Velocity * 180 / (radius * pi)

    Long Version:

    Box2d internally uses it's own distance unit (m) which is 0.02 pixels.

    The conversion is:

    1 [pixel] = 0.02 [m]

    or

    50 [pixel] = 1 [m]

    The set Velocity action and getVelocity expression already do the conversion without help, but the conversion isn't considered with Force or Impulse.

    Before I go any further I'd like to suggest that the mass expression is returning a bad value. The formula for mass with units is:

    Mass [d * m^2] = density [d] * area [m^2][/code:2iwgq6s7]
    Where [d*m^2] is the same as [kg]
    
    So for a 32x32 pixel square with density 1 the mass should be:
    [code:2iwgq6s7]area [m^2]= (height [pixel] * 0.02 [m/pixel]) * (width [pixel] * 0.02 [m /pixel]) = (32 * 0.02) * (32 * 0.02) [m^2] = 0.4096 [m^2]
    mass [d * m^2] = density [d] * area [m^2] = 0.4096 [d * m^2][/code:2iwgq6s7]
    But the mass expression returns 20.48 or 50 times 0.4096 which is incorrect since that makes the units [d*pixel*m].
    
    This is only important because if it were correct you'd only have to multipy by 50 instead of 50*50 or 2500 with the Force and Impulse equations.
    
    Torque is a bit trickier.  The equation for Torque is:
    [code:2iwgq6s7]Torque [kg*m^2*deg/s^2] = inertia [kg*m^2] * ang_accel [deg/s^2][/code:2iwgq6s7]
    
    [url=http://en.wikipedia.org/wiki/List_of_moments_of_inertia]Inertia is calculated differently for different shapes[/url].  For a square the equation is:
    [code:2iwgq6s7]Inertia = mass * (width^2 + height^2)/12[/code:2iwgq6s7]
    For mass we'll use 0.4096 and we'll need to covert height and width from [pixel] to [m] and we get:
    Inertia = 0.4096 * ((32*0.02)^2 + (32*0.02)^2)/12 =~ 0.02796...
    
    I then ran a test to apply a torque of 1 for 60 ticks. At the end the angular velocity was approximately 35.76. From that the acceleration could be calculated with acceleration=(final_speed-initial_speed)/time which ended up being 35.76.
    
    The numbers agreed with the equation when it was plugged in:
    torque = inertia * ang_accel
    1 ?= 0.02796 * 35.76 
    1 ~= 0.9998
    
    This link may also be useful as it predicts motion using equations much like yours.
    
    -cheers
  • For #1 are triggering a floodfill when just hitting a ceiling. It doesn't look like it is.

    For #2 I've noticed the snapping doesn't seem right at times. The equations I used do what they were designed to do: find which square on a staggered grid to snap to.

    I did a test to evaluate the equation.

    https://dl.dropboxusercontent.com/u/542 ... p_hex.capx

    The formula is about the same as in the bubble shooter capx I've made before. I also compared it to just picking the nearest grid sprite which would be perfect minus the need all the sprites. Anyway there are subtle differences in the gaps. My conclusion is a new formula needs to be found so that snapping isn't done to the nearest square but the nearest hexagon, which would mirror using picking nearest.

    A internet search for "snap to hex grid" would probably be the next step.

    After that the issue of snapping into walls or other jewels may still be there and require another solution.

  • As a note you get the speed from velocityX and velocityY with this calculation:

    speed = distance(0,0,velocityX,velocityY)

    or

    speed = sqrt(velocityX^2 + velocityY^2)

    which is the same, just whatever you prefer.

  • Another idea could be to use the function object.

    global number cur = -1

    On function "next"

    --- set cur to (cur+1)%Function.ParamCount

    --- set return value to Function.Param(cur)

    On any click

    --- Set text to Function.call("next", "apples","oranges","bananas")

  • cool

  • This works

    (time<5 | time>10)?"not now":"now"[/code:gn5necf3]
  • I'd have to see a capx as I don't know from your description.

  • Yes hard. You could use the multiplayer chat example as a base, or use the peerjs third party plugin. Both have the side effect of needing access to the internet to at least get going.

    Or maybe very easy. You could use the clipboard as the way to send messages. Just set the clipboard in one app and periodically check in the other app. Although it could be annoying to the user with the clipboard contents being changed. You could also do it be reading and writing to a certain file.