In GameMaker, how to bounce object further with the Bounce action? - gml

I've set it up so that when my character collides with a wall, it bounces (non-precisely, if that matters). However, I'd like it to bounce further than it currently does, and I don't see an option to adjust it. How should this be achieved?
Thanks!

On collision, increase the velocity of the object.

Related

could someone tell me why everything vibrates when the camera in my game moves?

I'm not sure why, but for some reason whenever the camera in my game moves, everything but the character it's focusing on does this weird thing where they move like they should, but they almost vibrate and you can see a little trail of the back of the object, although it's very small. can someone tell me why this is happening? here's the code:
x+= (xTo-x)/camera_speed_width;
y+= (yTo-y)/camera_speed_height;
x=clamp(x, CAMERA_WIDTH/2, room_width-CAMERA_WIDTH/2);
y=clamp(y, CAMERA_HEIGHT/2, room_height-CAMERA_HEIGHT/2);
if (follow != noone)
{
xTo=follow.x;
yTo=follow.y;
}
var _view_matrix = matrix_build_lookat(x,y,-10,x,y,0,0,1,0);
var _projection_matrix = matrix_build_projection_ortho(CAMERA_WIDTH,CAMERA_HEIGHT,-10000,10000)
camera_set_view_mat(camera,_view_matrix);
camera_set_proj_mat(camera,_projection_matrix);
I can think of 2 options:
Your game runs on a low Frames Per Second (30 or lower), a higher FPS will render moving graphics smoother (60 FPS been the usual minimum)
another possibility is that your camera is been set to a target multiple times, perhaps one part (or block code) follows the player earlier than the other. I think you could also let a viewport follow an object in the room editor, perhaps that's set as well.
Try and see if these options will help you out.
If your camera is low-resolution, you should consider rounding/flooring your camera coordinates - otherwise the instances are (relative to camera) at fractional coordinates, at which point you are at mercy of GPU as to how they will be rendered. If the instances themselves also use fractional coordinates, you are going to get wobble as combined fractions round to one or other number.

SKPhysicsBody float like a balloon

I'm sure this is somewhere already on the internet, but I can't seem to find it. Say I want to add some balloons that float upwards in a scene (where gravity is downwards for everything else). What's the best way to go about it?
So far, I have set the balloon's mass to almost nothing, and applied an upwards force to it. It seems to work okay, but I'm hoping there is a more appropriate way of doing it.
Thank you

How to code a random movement in limited area

I have a limited area (screen) populated with a few moving objects (3-20 of them, so it's not like 10.000 :). Those objects should be moving with a constant speed and into random direction. But, there are a few limitation to it:
objects shouldn't exit the area - so if it's close to the edge, it should move away from it
objects shouldn't bump onto each other - so when one is close to another one it should move away (but not get too close to different one).
On the image below I have marked the allowed moves in this situation - for example object D shouldn't move straight up, as it would bring it to the "wall".
What I would like to have is a way to move them (one by one). Is there any simple way to achieve it, without too much calculations?
The density of objects in the area would be rather low.
There are a number of ways you might programmatically enforce your desired behavior, given that you have such a small number of objects. However, I'm going to suggest something slightly different.
What if you ran the whole thing as a physics simulation? For instance, you could set up a Box2D world with no gravity, no friction, and perfectly elastic collisions. You could model your enclosed region and populate it with objects that are proportionally larger than their on-screen counterparts so that the on-screen versions never get too close to each other (because the underlying objects in the physics simulation will collide and change direction before that can happen), and assign each object a random initial position and velocity.
Then all you have to do is step the physics simulation, and map its current state into your UI. All the tricky stuff is handled for you, and the result will probably be more believable/realistic than what you would get by trying to come up with your own movement algorithm (or if you wanted it to appear more random and less believable, you could also just periodically apply a random impulse to a random object to keep things changing unpredictably).
You can use the hitTest: method of UIView
UIView* touchedView=[self.superview hitTest:currentOrigin withEvent:nil];
In This method you have to pass the current origin of the ball and in second argument you can pass nil.
that method will return the view with which the ball is hited.
If there is any hit view you just change the direction of the ball.
for border you can set the condition for the frame of the ball if the ball go out of the boundary just change the direction of the ball.

Bullet physics engine, how to freeze an object?

Using Bullet 2.76 I'm trying to freeze an object (rigid body) so that it instantly stops moving, but still responds to collisions.
I tried setting it's activation state to DISABLE_SIMULATION, but then it's virtually nonexistent to other objects. Furthermore, if objects "collide" with it when it's disabled, strange things begin to happen (object's falling through static bodies, etc.)
I suppose, temporarily converting it to a static rigid body could work, but is there an existing "native" way to achieve this on Bullet's side?
Edit: Is there a way to turn off gravity for a specific object?
The documentation is a bit lacking but one would assume that the method below could be used to disable gravity on a specific body:
void btRigidBody::setGravity(const btVector3 &acceleration)
Just set rigid body's mass to 0, then it become static...
http://bullet.googlecode.com/svn/trunk/Demos/HelloWorld/HelloWorld.cpp
There are functions for btRigidBody called setLinearFactor(x,y,z) and setAngularFactor(x,y,z) that allow you to limit motion along a specific axis and rotation about a specific axis respectively. Calling both functions with all 0's as arguments should stop all motion. Calling them again with all 1's will allow motion again.
Set the activation state to zero. This is what happens when the object sleeps naturally. Gravity and so forth will not take effect until it is woken again.
rigidBody->setActivationState(0);
Then just like any sleeping object, it will be woken on a collision or if you apply a force to it.
For this method to stop your actor you must call this every update frame.
void StopActor()
{
m_pRigidBody->setLinearVelocity(btVector3(0,0,0));
}
set the velocity and momentum to zero and set the mass to a really, really large number.

How can I detect a permanent collision with the Chipmunk Physics engine

I'm trying to play a "boing" sound when a ball shape hit's any other kind of shape. Which works. But works a little too well....
When the ball comes to rest, or starts to roll, it's in a permanent collision with whatever it's touching, so the "boing" sound fires constantly.
I can't find anything in the chipmunk documentation to tell me when two things are permanently colliding. So I'm thinking I will have to somehow figure it out myself, probably with some sort of timer that compare the last collision against the current collision. But that sounds hacky to me.
Has anyone tackled this issue? How did you solve it?
Couldn't you just play your "boing" sound when contact is BROKEN?
There is a callback for that in chipmunk, typedef void (*cpCollisionSeparateFunc)(cpArbiter *arb, struct cpSpace *space, void *data)
That way you get boings whenever it bounces, but not when it's just rolling along. 'course, you'll also get one when it rolls off of your shape, but that could be a feature depending on how you look at it.
I don't think that what I'm about to say is a good practice, but I'm sure it will solve your problem:
For each object, keep two state variables: (1) The last object collided with, (2) The last collision time.
Upon collision, only play a sound if the collided object is different (and a ball) OR a certain "delta time" has elapsed since the last collision. Then record the last collision stats.
This is pretty simple and very effective:
// In your ball interface
id lastCollisionObject;
double lastCollisionTime;
// When a collision occurs...
double now = GetTime();
id other = GetCollisionObject();
if ((now - lastCollisionTime) > 0.3 || other != lastCollisionObject) {
PlaySound(kBoingSound);
}
lastCollisionObject = other;
lastCollisionTime = now;
Shapes don't have velocity in chipmunk. The bodies they are attached to have it. You can access velocity like this: "myShape.body->v". I agree that you should just be able to check if the velocity is over a certain threshold to know when an 'impact' occurs. You can also check the rotational velocity to see if the ball is rolling.