Pull & Repulse Mechanics Help

This forum is currently in read-only mode.
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • I've been looking at construct for months, but this is the first time I actually tried something different than the tutorials.

    In short, this is what I was trying to make: A Zelda-esque game where to defeat an enemy you need to pull them with a wand and repulse them into a wall/other enemy.

    This is how the mechanic goes:

    1. Clicking on an enemy will pull the enemy towards you.

    2. As long as you hold your click, you can still move and the enemy will still be drawn into you.

    3. When the click is released, the enemy is repulsed into whichever direction you were aiming. The repulse power is inversely proportional to the distance between you and the enemy when released -- that is, the closer the enemy is to you, the more powerful the repulse power is.

    However, I barely managed to complete the first step. When I clicked an enemy it is drawn to me (using setForce) but I am clueless on how to make the enemy keep drawn into you while you hold the mouse click.

    I kinda get the concept (as long as an enemy is drawn to you AND LMB is down, pull the enemy towards you) but I don't know how to apply it in Construct.

    Thanks in advance

  • so you're using physics then?

    I haven't played the zelda game in question, so do you want them slowly drawn towards you as you hold? if so, what happens when they're right next to you? do they stay stuck there? These are questions I ask for the sake of this question, but also things that construct won't know until you tell it.

    But for starters:

    ----------------------------------------

    MouseKeyboard - Left Mouse Button is Down (Not on left mouse click)

    -----Continue to draw the enemy in some way depending on what you need* //assuming the enemy is always hovering in front of you in the direction you're facing: MouseKeyboard - On Left Mouse button released -----Set Force toward Position (hero.x,hero.y) Force: 0 - lerp(minimumforce,maximumforce, clamp(1-(distance(hero.x,hero.y,enemy.x,enemy.y)/maxdistance),0,1))

    -----------------------------------

    if you don't know what lerp does, try this tutorial:

    clamp keeps values within a certain range like clamp(x,min,max) will just give you x right back to you, unless it's lower than min, or higher than max, then it'll just give you min or max.

    so clamp(5,0,100) = 5

    clamp(-5,0,100) = 0

    clamp(999,0,100) = 100

    depending on whether you love math, and whether you understand lerp and clamp, that last part

    [quote:eoriejul] clamp(1-(distance(hero.x,hero.y,enemy.x,enemy.y)/maxdistance),0,1)

    will or won't make sense to you, feel free to ask if it doesn't make sense

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • When the objects is right next to the player, it stays there until the player repulses it. Your assumption is right.

    Let me read about lerp and try your guide, I'll tell you the result later tonight. Thanks

    Edit, if I am not mistaken, the last part

    clamp(1-(distance(hero.x,hero.y,enemy.x,enemy.y)/maxdistance),0,1)[/code:1pp4t9yt]
    
    Finds the distance between the hero and enemy compared to its maximum distance. Basically this ensures the closer the enemy gets to player, the stronger the repulsion force is. 
    
    And if I am not mistaken, lerp is used so that we always have the repulsion force set between the minimum and maximum value we wanted. Am I correct?
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)