"Throwing" objects with physics + drag&drop

This forum is currently in read-only mode.
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • 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.

  • 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:

    +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
  • Well first of all thanks

    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!

  • 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.

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • So fix it

    It's not anything that can't be corrected with further eventing.

  • 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

  • How to do it?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)