player push a ball
by Noah Gomes · in Torque 3D Professional · 05/17/2013 (8:08 am) · 15 replies
I need help with the player pushing a ball. I can shoot the ball and it will move. When I run into the ball with the car or with the player, it will not move. Here is code for the ball
datablock RigidShapeData( BouncingBoulder )
{
category = "RigidShape";
shapeFile = "art/shapes/rocks/boulder.dts";
emap = true;
// Rigid Body
mass = 1;
massCenter = "0 0 0"; // Center of mass for rigid body
massBox = "0 0 0"; // Size of box used for moment of inertia,
// if zero it defaults to object bounding box
drag = 0.0; // Drag coefficient
bodyFriction = 0.0;
bodyRestitution = 0.1;
minImpactSpeed = 5; // Impacts over this invoke the script callback
softImpactSpeed = 5; // Play SoftImpact Sound
hardImpactSpeed = 15; // Play HardImpact Sound
integration = 4; // Physics integration: TickSec/Rate
collisionTol = 0.1; // Collision distance tolerance
contactTol = 0.1; // Contact velocity tolerance
minRollSpeed = 10;
maxDrag = 0.5;
minDrag = 0.01;
triggerDustHeight = 1;
dustHeight = 10;
dragForce = 0.05;
vertFactor = 0.05;
normalForce = 0.05;
restorativeForce = 0.05;
rollForce = 0.05;
pitchForce = 0.05;
};
datablock RigidShapeData( BouncingBoulder )
{
category = "RigidShape";
shapeFile = "art/shapes/rocks/boulder.dts";
emap = true;
// Rigid Body
mass = 1;
massCenter = "0 0 0"; // Center of mass for rigid body
massBox = "0 0 0"; // Size of box used for moment of inertia,
// if zero it defaults to object bounding box
drag = 0.0; // Drag coefficient
bodyFriction = 0.0;
bodyRestitution = 0.1;
minImpactSpeed = 5; // Impacts over this invoke the script callback
softImpactSpeed = 5; // Play SoftImpact Sound
hardImpactSpeed = 15; // Play HardImpact Sound
integration = 4; // Physics integration: TickSec/Rate
collisionTol = 0.1; // Collision distance tolerance
contactTol = 0.1; // Contact velocity tolerance
minRollSpeed = 10;
maxDrag = 0.5;
minDrag = 0.01;
triggerDustHeight = 1;
dustHeight = 10;
dragForce = 0.05;
vertFactor = 0.05;
normalForce = 0.05;
restorativeForce = 0.05;
rollForce = 0.05;
pitchForce = 0.05;
};
About the author
#2
05/17/2013 (9:14 am)
It's been awhile since I've had the code in front of me for this but basically you need to apply an impulse in an onCollision callback in order to "push" the rigidshape. There are various snippets for this that I've posted over the years.... but you'll have to do some searching for them.
#3
05/17/2013 (9:43 am)
Ah, yeah - I didn't even think of that because I was making a game that uses rockets to move the ball and if the ball touches the player you die....
#4
05/17/2013 (11:21 am)
ok.......... When they hit the ball. Nothing happen
#5
05/17/2013 (6:08 pm)
So they pass through the ball unhindered? Or it stops them? The first is my definition of "nothing" in this context....
#6
05/17/2013 (6:45 pm)
it will stop them
#7
05/18/2013 (8:59 am)
Did you apply a vector impulse whenever the onCollision method is invoked for either the player/vehicle or the rigidshape boulder?
#8
05/18/2013 (11:36 am)
I'm looking for the code for that
#9
{
if (%col.getDataBlock().getName() $= "ball1") {
// Apply an impulse to the object we collided with
%eye = %obj.getEyeVector();
%vec = vectorScale(%eye, 10);
// Add a vertical component to give the item a better arc
%dot = vectorDot("0 0 1",%eye);
if (%dot < 0)
%dot = -%dot;
%vec = vectorAdd(%vec,vectorScale("0 0 2",1 - %dot));
// Set the objects position and initial velocity
%trans = %col.getTransform();
// Heres the position and rotation.
%pos = getWords(%trans, 0, 2);
%col.applyImpulse(%pos,%vec);
}
}
I am not a good programer
05/18/2013 (11:41 am)
function Armor::onCollision(%this,%obj,%col) {
if (%col.getDataBlock().getName() $= "ball1") {
// Apply an impulse to the object we collided with
%eye = %obj.getEyeVector();
%vec = vectorScale(%eye, 10);
// Add a vertical component to give the item a better arc
%dot = vectorDot("0 0 1",%eye);
if (%dot < 0)
%dot = -%dot;
%vec = vectorAdd(%vec,vectorScale("0 0 2",1 - %dot));
// Set the objects position and initial velocity
%trans = %col.getTransform();
// Heres the position and rotation.
%pos = getWords(%trans, 0, 2);
%col.applyImpulse(%pos,%vec);
}
}
I am not a good programer
#10
So change the $= "ball1" to $= "BouncingBoulder"
Let me know if that works for you.
05/18/2013 (11:47 am)
ball1 is the datablock name. The datablock above that you provided is called BouncingBoulder.So change the $= "ball1" to $= "BouncingBoulder"
Let me know if that works for you.
#11
05/18/2013 (12:29 pm)
it doesn't work,, I made a soccer ball and called ball1.
#12
05/19/2013 (8:33 am)
function RigidShapeData::onCollision(%data, %obj, %col, %vec, %speed)
{
//error("RigidShapeData::onCollision(" SPC %data.getName()@", "@%obj@", "@%col.getClassName()@", "@%vec@", "@%speed SPC ")");
// if it is colliding with itself or the terrain then ignore it
if (%obj == %col || %col.getType() & $TypeMasks::TerrainObjectType || %speed < 1)
return;
if (%col.getType() & $TypeMasks::ShapeBaseObjectType)
{
if (%obj.lastCollider = %col)
{
// we just ran into this, lets give it half a second before we apply another impulse
if (getSimTime() - %obj.lastColTime < 550)
return;
}
%velocity = %col.getVelocity();
%normal = vectorDot(%velocity, VectorNormalize(%velocity));
if(%normal < 15)
%multi = 8;
else
%multi = 8 / %normal;
%objPos = %obj.getPosition();
%colPos = %col.getPosition();
%vec = VectorNormalize(VectorSub(%objPos, %colPos));
%force = VectorScale(%vec, %col.getDatablock().mass * %multi);
%obj.applyImpulse(%objPos, %force);
%obj.lastCollider = %col;
%obj.lastColTime = getSimTime();
}
}
#13
05/19/2013 (2:11 pm)
I assume that goes in player.cs
#14
05/19/2013 (7:15 pm)
function RigidShapeData::onCollision(%data, %obj, %col, %vec, %speed)It goes wherever your RigidShape datablock is defined - that way it is easy to find later....
#15
05/19/2013 (7:46 pm)
that worked
Torque Owner Richard Ranft
Roostertail Games