"Throwing" objects with physics + drag&drop

For questions about using Classic.

Post » Sun Apr 26, 2009 10:34 am

I think the tile is clear enough. I'm sure it's possible to do, my question is how? I'm not really familiar with advanced stuff in construct, so I need help.

Also, is there a way to detect whether an object is at rest, without doing "previous position speed etc" = "current position speed etc"? And, to do that, how do I define object variables like previous speed etc?

Also, when I create a Hinge in an event, is there a way to remove it?

Thanks for trying to answer my questions in advance.
B
1
G
4
Posts: 9
Reputation: 1,043

Post » Sun Apr 26, 2009 11:06 am

Hi Nayon, and welcome to the forums... you have obviously posted before but this is the first time I've seen you around ;)

To answer some of your questions...

Yes you can to some things that will allow you to drag around physics objects. Just remember, that physics behaviour ONLY works by applying physics forces to it. You cannot assign other behaviours to physics objects as they will spaz out.

To make a simple click and darag function, you could do something like:

pseudocode:
[code:31jas7um]
+Mouse button is down
+Mouse is moving
-Apply force of MouseSpeed at angle MouseX, MouseY
[/code:31jas7um]

To find out if the mouse is moving you would need to compare coordinates. I'm not 100% sure how this would work, but I assume you would use "lerp" to calculate the difference in X and Y position of the cursorr.

Using "lerp" you should also be able to figure out the angle at which the cursor is moving, or just use the current X and Y coordinates of the mouse as the "launch" destination.

It all depends exactly HOW you want the objects to move. Are you picking them up and moving them "god style"? Are you throwing them like a half-life 2 phys-gun? Are you giving them momentum and "coaxing" them around the screen?

Answer this, and perhaps a clearer/simpler solution can be derrived.

Also, to find out if an object is moving or not (assuming you are talking about physics objects still) you should be able to compare the velocity of the object.

[code:31jas7um]
+PhysObject velocity equals or less than 0
-Do stuff


or


+PhysObject velocity greater than 27
+PhysObject velocity less than 132
-Do different stuff
[/code:31jas7um]

Lastly, hinges I believe cannot be broken without destroying one of the objects and recreating it in the same position using a loop. I use this in my tank battle game when repairing the treads (since it uses many small hinged physics objects). You can destry all objects in the required conditions, and recreate them instantly in the same X Y coordinates, but without re-hinging them.

If you need more specific details on this, then let me know I should be able to help you out pretty good on this bit ;)

Hope that helps!

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
45
S
17
G
37
Posts: 2,853
Reputation: 25,966

Post » Sun Apr 26, 2009 11:22 am

Well first of all thanks :D

Secondly, I'm talking about throwing objects "god style" as you said. But I also want to throw them away, ie dragging then releasing an object while the mouse is moving "throws" the object.

For some reason I can't ever observe the effect of setting forces of objects, it just seems to not work.

Thanks for the moving thing.

The hinge is about hinging an object to a point, not to an object. I guess I'll have to delete the object and recreate it.

Thanks!
B
1
G
4
Posts: 9
Reputation: 1,043

Post » Sun Apr 26, 2009 6:04 pm

Argh, I had a sample .cap I made a long time ago where you pick up and throw a physics ball with the mouse, but I can't find it. As I recall it was really simple to do, too.

I'm too braindead right now to recreate it, I might have a go later on.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sun Apr 26, 2009 8:20 pm

Oh hey, I found it :)

http://dl.getdropbox.com/u/529356/dragandtoss.cap

And yeah, it was simple... I just couldn't remember the exact method. Doesn't need Drag & Drop behavior, either.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Thu Apr 30, 2009 1:29 pm

I noticed something odd when playing around with this: the "left mouse button released" event isn't registered when the mouse cursor is outside the game window, but the "left mouse button is down" event is.
By trying to drag blocks outside the game window you can have multiple blocks with the "lock" variable set to 1. When you then click hold the left mouse button in the game window, all the blocks with the lock variable set to 1 will rush over to the mouse cursor. I'm sure this behaviour wasn't planned.
B
4
G
3
Posts: 39
Reputation: 978

Post » Thu Apr 30, 2009 7:18 pm

So fix it :)

It's not anything that can't be corrected with further eventing.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sat Oct 29, 2011 12:51 am

I would like to see this. But the link is broken :( I'm trying to write a little angry bunnies physics game. When I try to setVelocity to an object, it just drops off of the screen. I kind of want to sling shot it. Do I have to apply forces then to do this?

Brent
B
3
G
1
Posts: 1
Reputation: 552


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests