Wallpaper Engine

Wallpaper Engine

Not enough ratings
Drag boob
   
Award
Favorite
Favorited
Unfavorite
Age Rating: Everyone
Category: Asset
Asset Type: Script
Asset Genre: Interactive
Script Type: Boolean
File Size
Posted
35.979 KB
Apr 5, 2021 @ 5:34pm
1 Change Note ( view )

Subscribe to download
Drag boob

Description
'use strict';

const DRAG_MAX_DISTANCE = 30;

var activeDragBone = -1;
var dragDelta;

var shouldBounce = false;

var dragStart;

/**
* @param {Boolean} value - for property 'visible'
* @return {Boolean} - update current property value
*/
export function update(value) {
if (activeDragBone >= 0) {



if (!shouldBounce) {
var releaseDistance = thisLayer.getBoneTransform(activeDragBone).translation().subtract(input.cursorWorldPosition.add(dragDelta));
releaseDistance.z = 0;
if (releaseDistance.length() > 5) {
shouldBounce = true;
thisLayer.getTextureAnimation().setFrame(2);
}
}

var drag = input.cursorWorldPosition.subtract(dragStart);
var dragDist = drag.length();
drag = drag.divide(dragDist);
// Limit the distance to the max distance that was configured in the DRAG_MAX_DISTANCE constant at the top
drag = dragStart.add(drag.multiply(Math.min(DRAG_MAX_DISTANCE, dragDist)));
// Move the bone to the newly calculated drag distance
thisLayer.setBoneTransform(activeDragBone, thisLayer.getBoneTransform(activeDragBone).translation(drag.add(dragDelta)));





}
}

/**
* @param {ICursorEvent} event
*/
export function cursorDown(event) {
var numBones = thisLayer.getBoneCount();
activeDragBone = -1;
shouldBounce = false;
var bestDist = 200;
for (var b = 0; b < numBones; ++b) {
var bonePos = thisLayer.getBoneTransform(b).translation();
var delta = bonePos.copy().subtract(event.worldPosition);
var len = delta.length();
if (len < bestDist) {
dragStart = bonePos;
bestDist = len;
activeDragBone = b;
dragDelta = delta;
}
}


}

/**
* @param {ICursorEvent} event
*/
export function cursorUp(event) {
if (activeDragBone >= 0) {
thisLayer.getTextureAnimation().setFrame(0);


var skipBone = activeDragBone;
activeDragBone = -1;

if (shouldBounce) {
var releaseDistance = thisLayer.getBoneTransform(skipBone).translation().subtract(event.worldPosition.add(dragDelta));
releaseDistance.z = 0;

engine.setTimeout(function () {
var numBones = thisLayer.getBoneCount();
for (var b = 0; b < numBones; ++b) {
if (b != skipBone) {
var impactPos = thisLayer.getBoneTransform(skipBone).translation();
var impulseScale = Math.max(0, 200 - thisLayer.getBoneTransform(b).translation().subtract(impactPos).length());

thisLayer.applyBonePhysicsImpulse(b, releaseDistance.multiply(impulseScale * 0.2));
}
}

}, 100);
}
}
}

/**
* @param {Boolean} value - for property 'visible'
* @return {Boolean} - update current property value
*/
export function init(value) {
thisLayer.getTextureAnimation().stop();
}
3 Comments
futo Jan 13, 2022 @ 1:48am 
well these codes are from the official designer documentation sample projects; and since he has codes from 2 different samples meshed together I kinda wish he explained too
NuggetNuggetNugget Oct 16, 2021 @ 2:48am 
As others have said this is pretty much dead in the water with no explanation.
Bewie Apr 6, 2021 @ 1:40am 
how does this work?