Is there a Grab and FLING or Toss behavior?

Get help using Construct 2

Post » Thu May 02, 2013 4:30 am

Greetings,

I'm creating a physics based game and wanted to be able to grab an object, then upon release - have the object go forth with momentum based on my drag motion.

I know there is a Grab and Drop behavior, but it just drops upon release - with no momentum.

Any way to do this?

Thanks for any help or input..
B
4
Posts: 10
Reputation: 245

Post » Thu May 02, 2013 5:29 am

Try something like this

var disc.touchid = -1
var force = 200 // tinker with this to get it to feel right


onTouch disc
set disc.touchid = touch.touchid

isTouching
disc.touchid >= 0
--> disc force=distance(discxy, touchxyforid(disc.touchid))*force, disc angle = angle(discxy, touch.xyforid(disc.touchid))

onAnyEndTouch
disc.touchid = touch.touchid
--> disc.touchid = -1

B
87
S
18
G
9
Posts: 2,455
Reputation: 14,834

Post » Fri May 03, 2013 7:02 am

Thanks but I'm relatively new to Construct..

What is disc.touchid? Where and how to change? What is var? declaring variable?

I understand the very basics of Events Behaviors Actions.. I understand that 'isTouching' is a behavior and know where to find that. Same with 'onAnyEndTouch'..

But everything else is vague to me as to what you are doing. 'var disc.touchid' 'var force' where to set this?

Sorry for being a noob =} Thanks for the help , I do appreciate it
B
4
Posts: 10
Reputation: 245

Post » Fri May 03, 2013 9:21 am

It's funny how often this topic comes up. Here's an example that I made a while ago for someone else: example capx.
B
56
S
15
G
10
Posts: 910
Reputation: 11,952

Post » Fri May 03, 2013 11:46 am

I wrote it like this:
On object click, lerp or set the X and Y to the mouse.
Store the current velocityX and Y of the physics object while it's being dragged.
On mouse release, set the objects new velocity x and velocity y to the variables you stored.
B
10
S
3
G
3
Posts: 234
Reputation: 3,467

Post » Fri May 03, 2013 2:12 pm

@Geometrix
Hey, that's a great example ! But there are two problems :
- the balls goes through the green walls when speed is high and well as when it is dragged.

Is there a way to correct that ?
B
21
S
9
G
4
Posts: 197
Reputation: 4,105

Post » Fri May 03, 2013 4:23 pm

I was using another program, where I was encountering the same issues with balls clipping through collisions at seemingly random times.. but also notice when it was going at a faster speed , more specifically - a movable object colliding with a non-movable object, would clip. That's why I tried to use this program - but maybe these drag and drop interfaces are too basic to prevent such intricate detections.

I will experiment more tonight, thanks all for the input. I didn't know this came up so often - I did a search and couldn't find much on the toss/fling stuff..
B
4
Posts: 10
Reputation: 245

Post » Fri May 03, 2013 8:13 pm

@Laurent, I'd suggest adding an event on ball collision with the wall, drop the drag and drop, and set the ball physics bullet property to true.
B
56
S
15
G
10
Posts: 910
Reputation: 11,952

Post » Fri May 03, 2013 9:16 pm

Thanks everybody for the input.

The community here really is helpful unlike some others that I have experienced.

Cheers.
B
4
Posts: 10
Reputation: 245

Post » Sat May 04, 2013 9:09 am

I have the free version of Construct 2 so it only publishes to HTML5.

But I noticed - everything works great except after the first few seconds when I Preview it in browser (Firefox) - the scene 'freezes' for a few seconds then resumes perfectly. From then on out, it doesn't freeze and everything runs smooth until I close session. Is this an issue that is caused by code or just because I'm in free version previewing in browser?

B
4
Posts: 10
Reputation: 245

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 16 guests