Game Development Community

Physics

by Stephen · in Torque Game Engine · 11/28/2004 (5:49 pm) · 5 replies

I have a question about physics. I want some physics in my game like Half-Life 2. Not the ragdoll but where u can push and shoot the items around. I have got the ODE physics in Torque but the ODE is not working out the way I want it to. I have added this script in the player.cs to push the items. IN BOLD

function Armor::onCollision(%this,%obj,%col,%vec,%speed)
//function Armor::onCollision(%this,%obj,%col)
{
if (%obj.getState() $= "Dead")
return;

// Try and pickup all items
if (%col.getClassName() $= "Item")
%obj.pickup(%col);

if (%col.getDataBlock().getName() $= "Box") {
// Apply an impulse to the object we collided with
%eye = %obj.getEyeVector();
%vec = vectorScale(%eye, 0.8);

// Set the object's position and initial velocity
%trans = %col.getTransform();

// Heres the position and rotation.
%pos = getWords(%trans, 0, 0.5);
%col.applyImpulse(%pos,%vec);
}

}

It somewhat pushes the item but if u hit the item in a different way, it spins out of control. Is there a different way to get the physics working like Half-Life 2?

Thanks,
-Stephen

#1
11/28/2004 (5:53 pm)
%pos = getWords(%trans, 0, 0.5);


thats sort of wierd
#2
11/28/2004 (6:51 pm)
A friend of my sent me this code. I'm not sure if its right but it pushes the item but its not how I want it to move. Anyway ideas to go ODE working like the physics in HL2?
#3
11/28/2004 (7:16 pm)
ODEItem
#4
11/28/2004 (7:26 pm)
What is the difference between Rigid Shape Class and ODEItem?
#5
11/28/2004 (8:05 pm)
The rigid shape class is using the rigid class that the vehicles use for their simulation, just without any wheels or anything (as far as i know).

The ODEItem sets up an ode world and adds the item to it, along with any constants for the item (mass, friction etc). These constants and the collisions torque provides are solved by ODE and the new transformations and velocities are given back to torque.

To get Hl2 sort of physics (picking up and throwing things) you will need to modify the ODEItem class as it doesnt really have much player interaction stuff. I dont think a player can walk on an ODEItem for example. However, ODE does have an interface that could be exposed to TorqueScript for applying impulses to objects.