[quote="Dines":u3qrhsk8]So for example, positioning an object to the mouse coordinates, so you can make a brick follow the mouse, and move/slow down with the force of the mouse. So you could use the mouse to pick up an object and wack other objects with it.
I suppose you'd do it by checking where the mouse is, and where the object is, and working out how much force it would need to have moved to that position.
You could do it manually by setting up some "lastMouseX" and "lastMouseY" variables, then check them against the current mouseX and mouseY. You could calculate speed and direction that way, and translate it to the object you're dragging around. Even if you're "teleporting" it to the mouse coord every frame, if you're manually setting it's x and y velocities then other objects will still react to it in a proper way.
As a test, I created two objects and added physics movement to them. Then I made this event:
- Sprite: Set velocity to (20,0)
- Sprite: Set X to mouseX
- Sprite: Set Y to mouseY
When I move the mouse around, the sprite sticking to it jitters, because it's trying to "escape," but I can drag it into the other sprites and they'll fly off toward the right as if they were hit naturally. It even calculates the angles of impact correctly, so they're not just flying straight to the right, but angling up or down depending on where they made contact.
If you were fully calculating the speed and trajectory by doing something like comparing "lastMouseX" with "mouseX," you might be able to avoid the jitter that comes with manually updating the velocity of the object you're dragging.
Alternately, when you click to drag an object, you could make it invisible, then position a "dummy object" that matches it at the mouse's xy coord. Since it's just a regular sprite with no physics, it wouldn't jitter. Then when you release the object, discard the dummy and make your original object visible again.
With some clever collision routines you could even check to see if there's an object to impact with between lastMouseX and mouseX, and change the mouse position manually to compensate for it so that you're not intersecting things. Hell, you might even be able to fake velocity, mass, etc. for the mouse itself by manually updating it's coordinates. I'll have to play around with it some to see what I can come up with.
[quote="Ashley":u3qrhsk8]It'd be great to have a platform movement who could go round shoving bricks and such.[/quote:u3qrhsk8]
Well, you already can if you do it custom. I made a platform prototype where the player input changes the sprite's velocity and such. You can also "kick" objects around. It wasn't terribly difficult, really. It took longer to comment it than it did to make.
Here's a .cap:
Just one small bug that I can't be bothered with figuring out right now, and that is sometimes the kick collision stops registering. I think it has to do with not defining specifically which object to kick, but I can't be arsed to fix it right now. Even so, it still works pretty well as a proof of concept.