Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to convert elastic constraint so it works as a billiard cue ball works. #632

Closed
UsmanMuhammad opened this issue Jun 26, 2018 · 0 comments
Labels

Comments

@UsmanMuhammad
Copy link

Hi,

I am using this snippet from slingshot.js which has this elastic constraint. I want to make it work like billiard cue ball, that when the user pushes, it should have the elastic behavior but then it should move straight. But due to pointA it doesn't work for me.

here is the snippet:
var anchor = { x: cue.position.x, y: cue.position.y },
elastic = Constraint.create({
pointA: anchor,
bodyB: cue,
stiffness: 0.05,
render: {
lineWidth: 0.5
}
});

Events.on(engine, 'tick', function() {
if (mouseConstraint.mouse.button === -1 && (cue.position.x > 170 || cue.position.y < 330)) {
elastic.bodyB = cue;
//want to update the pointA here but not able to.
}
});

var mouse = Mouse.create(render.canvas),
mouseConstraint = MouseConstraint.create(engine, {
mouse: mouse,
constraint: {
stiffness: 0.2,
render: {
visible: false
}
}
});

World.add(world, mouseConstraint);

I know it's a rookie question to ask, but please any help would be appreciated.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants