# Pull & Repulse Mechanics Help

For questions about using Classic.

### » Tue Apr 19, 2011 10:49 am

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.

B
1
G
1
Posts: 2
Reputation: 429

### » Tue Apr 19, 2011 12:53 pm

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:
----------------------------------------
[color=#404040:eoriejul][size=90:eoriejul]
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))
[/size:eoriejul][/color:eoriejul]
-----------------------------------
if you don't know what lerp does, try this tutorial: viewtopic.php?f=8&t=8735

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)[/quote:eoriejul]
will or won't make sense to you, feel free to ask if it doesn't make sense
Spriter Dev
B
91
S
21
G
12
Posts: 3,246
Reputation: 16,573

### » Wed Apr 20, 2011 11:01 am

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
[code:1pp4t9yt]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?
B
1
G
1
Posts: 2
Reputation: 429

Return to Help & Support using Construct Classic

### Who is online

Users browsing this forum: No registered users and 0 guests