How to use pymunk.Body.update_velocity(body, gravity, damping, dt) to dampen the mass. I know I can use global damping here but I want to add more masses later on and have custom damping for each one, and so I want to learn how to deploy body-specific damping. I have the following questions
How to use pymunk.Body.update_velocity
Can I leave gravity blank if I don't want custom gravity. Or should I just write space.gravity
What is dt here and how do I determine that
Did you find the example in the documentation here: http://www.pymunk.org/en/latest/pymunk.html#pymunk.Body.velocity_func ?
You need to define a custom velocity function somewhere, and then set it on the body you want it. So preferably you define it before you create the bodies. In this function you can call the existing default velocity function (pymunk.Body.update_velocity) if you want, but that is not a requirement. It depends on if you want to write all code to update velocity of the body yourself, or if you want to just modify it a bit with the existing code as a base. Since you only want to modify the damping I think its easiest to call the default function.
When you call the default v function you can send in the same gravity unmodified as you get it in your custom function.
dt is the delta time. I see now the docs could be improved here, I will make a note. So the dt is the same value as the dt sent to space.step(dt) function in your simulation loop.
All in all, I think something like this would do (you just need to adjust the calculation of modified_damping to the logic you want):
def custom_damping(body, gravity, damping, dt):
modified_damping = body.custom_damping * damping
pymunk.Body.update_velocity(body, gravity, modified_damping, dt)
body.custom_damping = 0.31415
body.velocity_func = custom_damping
(if you dont want to set a variable on the body you can of course do it in some other way. Lets say you want all bodies to have 2x the damping compared to normal you could do modified_damping = 2 * damping instead, and remove the body.custom_damping property.
Related
How do I instantiate an effect with a specific wet setting? I want to be able to create a new synth with updated effect parameters upon a range input change. However, I can't figure out how to make the wet/dry balance be anything but 100% wet. Is there a way to create an effect with a specific wet parameter? Something along the lines of
newDelay = new Tone.PingPongDelay(.5,.5).wet(.5)? Or would I have to assign the effect to a variable and access it like newDelay.wet = .5 after instantiating it?
To create an effect with a specific wet property, you can pass your options as an object like so:
const delay = new Tone.PingPongDelay({wet: 0.5, delayTime: "8n", feedback: 0.5});
Most Tone.js effects have different properties for that "options" object. You can find their documentation under the Constructor heading in the docs.
For instance, here's the reference for PingPongDelayOptions.
I am using statsmodels to fit a Local Linear Trend state space model which inherits from the sm.tsa.statespace.MLEModel class using the code from the example in the documentation:
https://www.statsmodels.org/dev/examples/notebooks/generated/statespace_local_linear_trend.html
The state space model and Kalman filter should handle missing values naturally but when I add some null values the state space model outputs nulls. In another example in the docs, implementing SARIMAX it appears that missing data appears to be handled automatically:
https://www.statsmodels.org/dev/examples/notebooks/generated/statespace_sarimax_internet.html
Is there a way to handle missing values in the same way for a Local Linear Trend model?
Chad Fulton replied to the issue I raised on github:
https://github.com/statsmodels/statsmodels/issues/7684
The statespace models can indeed handle NaN values in the endog variable. I think the issue is that in this example code, the starting parameters are computed as:
#property
def start_params(self):
return [np.std(self.endog)]*3
To handle NaN values in the data, you'd want to replace this with:
#property
def start_params(self):
return [np.nanstd(self.endog)]*3
This worked.
This is my code for the enemies in my game
//Collision
if (place_meeting(x,y,Object_Wall))
{
speed = 0
direction = point_direction(x,y,Object_Wall.x,Object_Wall.y) + random_range(160,200)
speed = sp / 2
time = random_range(room_speed * 0.75,room_speed * 3)
}
When the zombie hits a wall, it should turn back and walk the other way.
This works most of the time but sometimes they will just drift through walls and if they are following the player and he goes next to a wall they go through it.
I don't know why it doesn't work sometimes and would like help to fix this.
I am using Object_Wallas a parent object and they work with it but the problem occurs with it's children.
When you use point_direction(x,y,Object_Wall.x,Object_Wall.y), it's not object which was found using place_meeting(x,y,Object_Wall).
place_meeting(x,y,Object_Wall) will check collsion with all instances of object Object_Wall. But when you use in point_direction object id instead instance id, GM will take first (in creation order) instance of object Object_Wall.
You can take instance id using, for example, collision_circle function.
But I recommend use Collision event and other keyword inside it.
I was trying to get which vertex of a Feature has been modified. It seems that featuremodified event does not supply this information.
this is important because I will have to post the modification to the server. I dont want to post the whole feature object because of one single vertex change.
I am using OpenLayers v2.13.1
You need to hook into the vertexmodified callback of OpenLayers.Layer.Vector. This is triggered by the dragVertex function of OpenLayers.Control.ModifyFeature, see line 479 here http://trac.osgeo.org/openlayers/browser/trunk/openlayers/lib/OpenLayers/Control/ModifyFeature.js
The vertexmodified function receives a vertex, a feature and a pixel, so you would write something like this, assuming an OpenLayers.Layer.Vector called vector:
vector.events.register('vertexmodified', this, function(vertex, feature, pixel){
//do something with the vertex
});
I wonder how could I get the correct palm rotation angle (along Y-axis) from Leap Motion (I'm using the latest LeapJS API)?
I have tried both rotationAngle(sinceFrame) method and the frame._rotation. However, the rotationAngle() returns a very small value close to 0, which seems to be the rotation angle calculated based on the current frame (how to define the sinceFrame in Leap.loop(function(frame)){}, as it seems only records data from current frame).
And the frame._rotation returns a 3*3 matrix (which I've no idea about what is it, as it's not included in the API documentation). Therefore, I wonder if there's any way to get the correct rotation angle of Y-axis from these methods?
The latest version of the leap.js library includes a roll() function as a member of the Hand object. (It also has pitch() and yaw(), if roll() isn't all you want.) The roll() function is defined as:
Hand.prototype.roll = function() {
return Math.atan2(this.palmNormal[0], -this.palmNormal[1]);
}
As an aside, since you don't need to use rotationAngle() to get the current palm angles, the rotationAngle() function gives you the rotation that has occurred between two frames. For sinceFrame, you can either store a reference to the starting frame or get a past frame from the history buffer maintained by the Controller object. Although the Leap.loop() function doesn't give you access to its Controller object directly, you should be able to create your own. Note that frame._rotation is an internal variable that is used in the calculation of the transformations between two frames. It isn't much use on its own.