Hi Efrint,
I tried to translate your original message. That did not go so well. I am not sure where you should really put Newton question. I would think as long as you put Newton in the title either here or in Scripting forum would be about as good as anywhere. That's just my opinion.
Anyway, you can create a Newton moving with cursor bouncing ball by adding a new Newton material to the newtonScript2.wdl
Add this new newton material variable in declarations:
var rubber_material;
Add these skills in Declarations:
define SPEED_X, skill9;
define SPEED_Y, skill10;
define SPEED_Z, skill11;
define move_me, skill12;
Add this below NewtonWoodEnt action:
// uses mass, linear_drag, angular_drag_x, angular_drag_y, angular_drag_z, health, shape_factor, collision_groupId, collision_sph_box, start_active, compound_collision, destructible, spawn_children;
action NewtonBallEntity
{
NewtonCreateGravityEntity (rubber_material);
while (1)
{
if (key_cuu == on)
{
my.speed_x = 2 * time;
}
if (key_cud == on)
{
my.speed_x = -2 * time;
}
if (key_cul == on)
{
my.speed_y = 2 * time;
}
if (key_cur == on)
{
my.speed_y = -2 * time;
}
if ((key_cuu == off) && (key_cud == off))
{
my.speed_x = 0;
}
if ((key_cul == off) && (key_cur == off))
{
my.speed_y = 0;
}
if(my.SPEED_X || my.SPEED_Y)
{
my.MOVE_ME = ON;
NewtonGSScriptEvent();
my.MOVE_ME = OFF;
}
wait(2);
}
}
Add this in NewtonGSScriptEvent function:
if(my.MOVE_ME == ON)
{
// copy impact point on target
newtonImpulseRecord[0] = my.x;
newtonImpulseRecord[1] = my.y;
newtonImpulseRecord[2] = my.z;
// copy direction of push force
newtonImpulseRecord[3] = my.x - my.SPEED_X;
newtonImpulseRecord[4] = my.y - my.SPEED_Y;
newtonImpulseRecord[5] = my.z + .1; // give some top spin
// copy the push mass
newtonImpulseRecord[6] = 10;
// copy the some push speed, you may have to play with this
newtonImpulseRecord[7] = 5;
NewtonBodyAddImpulse (body, newtonImpulseRecord);
}
Add this in the NewtonSetupSystem() function: (notice how I set elasticity to .9)
// set material interaction propeteries (rubber_material, rubber_material)
NewtonMaterialSetFriction (rubber_material, rubber_material, 1.0, 1.0);
NewtonMaterialSetElasticity (rubber_material, rubber_material, 0.9);
NewtonMaterialSetDepthRecover (rubber_material, rubber_material, 0.2);
Now you can save newtonScript2.wdl. Close WED if it is open. Open WED place a sphere in your level. Place it up in the air. Open properties-behavior. Set action to NewtonBallEnt, set mass = 1.0, linear_drag, angular_drag_x,_y,_z all to 0.1. Check the flags for collison_sph_box and start_active. Build the level and run. The ball should fall from the air and bounce up and down a while. Use cursor keys to move.
That reminds me, when I added blocks to level the the newton_ball.mdl that came with Newton would pass through them for some reason. I made my own sphere(ball) model and it worked fine.
I hope that is close to what you wanted. It may need some fine tuning, but that ball moves, bounces around, and spins, so it should get you started.
Later,
Loco
Last edited by Locoweed; 01/29/05 13:58.