Object with gravity
by Anna Lichszteld · in Torque Game Engine · 02/22/2003 (10:00 pm) · 15 replies
hi,
I'm new in Torque so I need your help guys.
I would like to make coconut falling down from palm tree when player hits the palm.
I know that I can simply add trigger to "launch" coconut falling, but I don't know what kind of existing object use to get the effect.
Standard Static object has no physics, Item class has something but it doesn't look useful in that situation.
Any idea what kind of object should I use and how? Is it possible to do this in script only or I have to write some new class?
Thanks for any help
Best regards
Ania
I'm new in Torque so I need your help guys.
I would like to make coconut falling down from palm tree when player hits the palm.
I know that I can simply add trigger to "launch" coconut falling, but I don't know what kind of existing object use to get the effect.
Standard Static object has no physics, Item class has something but it doesn't look useful in that situation.
Any idea what kind of object should I use and how? Is it possible to do this in script only or I have to write some new class?
Thanks for any help
Best regards
Ania
#2
If my current solution doesn't work I will use yours idea.
In the meantime I tried to use coconut-projectile and it looks quite good because I can apply bouncing without too much afford.
Anyway I have a basic problem - coconut is not colliding with my vehicle and I have no idea why it happens.
What do you think about it?
Greetings
Ania
02/23/2003 (4:05 am)
Thanks a lot for help. If my current solution doesn't work I will use yours idea.
In the meantime I tried to use coconut-projectile and it looks quite good because I can apply bouncing without too much afford.
Anyway I have a basic problem - coconut is not colliding with my vehicle and I have no idea why it happens.
What do you think about it?
Greetings
Ania
#3
02/23/2003 (6:57 am)
Projectiles are already set to collide with vehicles, so if your coconut projectile is not colliding, most likely either your vehicle doesn't have a collision mesh or the collision mesh has concave surfaces. Feel free to email me any more details you might have on the problem.
#4
My co-worker changed the CastRay method in ShapeBase.cc and it seems to work properly now.
He replaced
> if (mDataBlock->LOSDetails[i] != -1)
with
> if (mDataBlock->collisionDetails[i] != -1)
Best regards
Ania
02/24/2003 (10:39 pm)
Hi again,My co-worker changed the CastRay method in ShapeBase.cc and it seems to work properly now.
He replaced
> if (mDataBlock->LOSDetails[i] != -1)
with
> if (mDataBlock->collisionDetails[i] != -1)
Best regards
Ania
#5
You could make a CoconutTreeStatic, i.e. a StaticShape, and give it an onAdd() method that creates a couple of StaticCoconut objects automatically at some offset or node position in the tree model. Add an onCollision method that plays a bumping sound, and a bump animation, then creates 2 Coconut Items and deletes the CoconutStatic objects. The Coconut objects will fall to the ground using the existing physics system and paramters in the datablock.
In the StaticCoconut, i.e. StaticShape object, give it an onCollision method that spawns a Coconut, i.e. Item and deletes itself. The Item can then just drop to the ground using the existing system physics and parameters in the datablock, then you can pick it up. Just make the Coconut the same shape, size, and texure as the CoconutStatic.
What you should wind up with is a coconut tree that will drop coconuts when you bump it and the coconuts will also drop if they are shot at with a gun.
Sounds like fun.
Cheers,
Robert
02/24/2003 (10:59 pm)
Items can bounce too. You could make a CoconutTreeStatic, i.e. a StaticShape, and give it an onAdd() method that creates a couple of StaticCoconut objects automatically at some offset or node position in the tree model. Add an onCollision method that plays a bumping sound, and a bump animation, then creates 2 Coconut Items and deletes the CoconutStatic objects. The Coconut objects will fall to the ground using the existing physics system and paramters in the datablock.
In the StaticCoconut, i.e. StaticShape object, give it an onCollision method that spawns a Coconut, i.e. Item and deletes itself. The Item can then just drop to the ground using the existing system physics and parameters in the datablock, then you can pick it up. Just make the Coconut the same shape, size, and texure as the CoconutStatic.
What you should wind up with is a coconut tree that will drop coconuts when you bump it and the coconuts will also drop if they are shot at with a gun.
Sounds like fun.
Cheers,
Robert
#6
Nice infos. What should I do to make the coconuts (to follow this exemple) bounce when I hit them ?
In my case, I just want to have items that bounce when hited with player or vehicles. I've been able to make them move by shooting at it, but actually, when I run to them(vehicles & players), they are like rocks and stays right there.
04/25/2003 (8:44 am)
Robert,Nice infos. What should I do to make the coconuts (to follow this exemple) bounce when I hit them ?
In my case, I just want to have items that bounce when hited with player or vehicles. I've been able to make them move by shooting at it, but actually, when I run to them(vehicles & players), they are like rocks and stays right there.
#7
04/25/2003 (9:02 am)
i think you would want to play with the elasticity and friction parameters.
#8
But badly, I can only make them move (and now bounce) when shooting a projectile at them. If I run onto it with my vehicle or player, it's still a rock, like a .dif (building). I don't know why the projectile make it react but not my players. It's probably something with my script with the "onCollision" function. Or "onImpact" ?! Here's what I tryed that was taken from the Crossbow codes :
I don't have an "onImpact" function actually.
Thanks for any other tips :)
04/25/2003 (10:00 am)
lol, that's cool ! Now my items bounce, hehe, really fun . Thanks Robert!But badly, I can only make them move (and now bounce) when shooting a projectile at them. If I run onto it with my vehicle or player, it's still a rock, like a .dif (building). I don't know why the projectile make it react but not my players. It's probably something with my script with the "onCollision" function. Or "onImpact" ?! Here's what I tryed that was taken from the Crossbow codes :
function Cerise::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
// // Apply damage to the object all shape base objects
if (%col.getType() & $TypeMasks::ShapeBaseObjectType)
%col.damage(%obj,%pos,%this.directDamage,"CrossbowBolt");
//
// // Radius damage is a support scripts defined in radiusDamage.cs
radiusDamage(%obj,%pos,%this.damageRadius,%this.radiusDamage,"RifleBullet",%this.areaImpulse);I don't have an "onImpact" function actually.
Thanks for any other tips :)
#9
function CoconutTree::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
// check if the colliding object is a player or vehicle
if (%col.getType() & ($TypeMasks::PlayerObjectType) | $TypeMasks::VehicleObjectType))
{
%coconut= new Item()
{
position = %obj.getTransform();
dataBlock = Coconut;
collideable = "0";
static = "0";
};
MissionCleanup.add(%asteroid);
}
}
Something along these lines. You will want to use something other than %obj.getTransform() for the position. You can add a dynamic variable to the CoconutTree datablock and use it as a value to add to Z of the transform to compute the drop location.
04/25/2003 (11:11 am)
Your condition should probably include the PlayerObjectType and VehicleObjectType mask.function CoconutTree::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
// check if the colliding object is a player or vehicle
if (%col.getType() & ($TypeMasks::PlayerObjectType) | $TypeMasks::VehicleObjectType))
{
%coconut= new Item()
{
position = %obj.getTransform();
dataBlock = Coconut;
collideable = "0";
static = "0";
};
MissionCleanup.add(%asteroid);
}
}
Something along these lines. You will want to use something other than %obj.getTransform() for the position. You can add a dynamic variable to the CoconutTree datablock and use it as a value to add to Z of the transform to compute the drop location.
#10
04/26/2003 (10:24 am)
Oops, replace asteroid with Coconut, missed that when I pasted this in and made some changes.
#11
My ItemObject
When shoot a projectile at them, they do exacly what I want : They have an impulse so they are pushed away and bounce. It's moving to all direction (XYZ) so this is perfect.
When I hit them with my player and vehicles, they don't get the impulse so they don't move(rocks). But the weirdness of it is that if my vehicle is under the item, the item know that my vehicle is there so it bounce on my vehicle like it is supposed to do and if I go away, it drop to the ground. It's like if I can move the item by pushing it (with vehicle an player) only in the Z position, but not XY.
My StaticObject
I can shoot and destroy them with a projectile, so they get damage. But they don't move.
When I hit them with player and vehicles, they don't move and don't seems to get damage. I've put an ECHO that say that they get the damage in the onCollision function.
Nway, what I want is what the item are doing. I don't really need to destroy them so I'll continue with the itemObjects that is close to work. If I understand, static is there to don't move :)
The difference with the coconut exemple and what I'm trying to do is that I don't have 2 objets (A coconutTree and coconuts items). I just have an item on the level that I'd like to push and move with my player and vehicles (like a ball or box). It's working with my projectiles so I'm thinking there is a way to do it with player and vehicle, but maybe not without other C++ modif (?). :)
Thanks much for the help !
04/26/2003 (11:42 am)
Robert, first thanks much for the help. I'm trying to figure all this but I think my problem is that I'm confuse with ItemObject and StaticObject. I tryed both with differnt result :)My ItemObject
When shoot a projectile at them, they do exacly what I want : They have an impulse so they are pushed away and bounce. It's moving to all direction (XYZ) so this is perfect.
When I hit them with my player and vehicles, they don't get the impulse so they don't move(rocks). But the weirdness of it is that if my vehicle is under the item, the item know that my vehicle is there so it bounce on my vehicle like it is supposed to do and if I go away, it drop to the ground. It's like if I can move the item by pushing it (with vehicle an player) only in the Z position, but not XY.
My StaticObject
I can shoot and destroy them with a projectile, so they get damage. But they don't move.
When I hit them with player and vehicles, they don't move and don't seems to get damage. I've put an ECHO that say that they get the damage in the onCollision function.
Nway, what I want is what the item are doing. I don't really need to destroy them so I'll continue with the itemObjects that is close to work. If I understand, static is there to don't move :)
The difference with the coconut exemple and what I'm trying to do is that I don't have 2 objets (A coconutTree and coconuts items). I just have an item on the level that I'd like to push and move with my player and vehicles (like a ball or box). It's working with my projectiles so I'm thinking there is a way to do it with player and vehicle, but maybe not without other C++ modif (?). :)
Thanks much for the help !
#12
I've just found your ressource "Moveable, Destroyable, Mission Area Aware ITEMS". Are you able to apply a push to your asteroids when hitting them with your spaceship (if not destroyed)?
I'll study your codes :)
04/26/2003 (12:54 pm)
Robert,I've just found your ressource "Moveable, Destroyable, Mission Area Aware ITEMS". Are you able to apply a push to your asteroids when hitting them with your spaceship (if not destroyed)?
I'll study your codes :)
#13
For those interested, here is what was missing in my onCollision function to be able to move the item :
04/26/2003 (1:25 pm)
OMG, I got it ! :)))For those interested, here is what was missing in my onCollision function to be able to move the item :
%this.setVelocity(%obj.getVelocity()); %vel1 = getword(%obj.getVelocity(), 0); %vel2 = getword(%obj.getVelocity(), 1); %vel3 = getword(%obj.getVelocity(), 2);
#14
04/26/2003 (1:43 pm)
Gilles, no, when my ship hits an asteroid, it is destroyed without exception.
#15
04/26/2003 (3:25 pm)
This make sens, thinking realistic (Asteroids and spaceships) :) I'd like to thanks you again for helping. Your replys makes me find the solution by making me try new things I hadn't though of. Your things plus mine made it. I can't wait to see your project in space. Looks like really fun. Really intriguing to see a space game in torque.
Torque 3D Owner Bruce Wallace
I would look into the Item objects a bit more, I think the effect you want to produce could be done using them and the player would also be able to pick them up. I would start by searching inventory.cs for "throw" "throwObject" and item.cs for "onThrow". and make a similar "drop" function and have your tree drop the item when triggered.
Hope that helps you get started, and if you need further examples I can work up a simple function.
Bruce
Edit: You could possibly use the existing throw function as well and just put something like "throwforce = 1;" in your item datablock. Just another Idea that crossed my mind.