Vehicles using energy.
by Stephen · in Torque 3D Professional · 08/03/2013 (4:53 pm) · 7 replies
1) How would someone go about making a vehicle use energy to move forward or backwards?
2) How would you make the vehicle take damage when hitting something (staticshape like a rock or tree)? The higher the speed the higher the damage.
3) Then have two items that the vehicle can drive over to get more energy and repair the damage.
2) How would you make the vehicle take damage when hitting something (staticshape like a rock or tree)? The higher the speed the higher the damage.
3) Then have two items that the vehicle can drive over to get more energy and repair the damage.
#2
Here's my scripts; gameCore.cs player.cs
08/03/2013 (7:05 pm)
I think that works but for some reason the damage isn't getting applied. I'm getting this error message in the console log.c4Armor::onImpact -> DefaultPlayerData for just ran into TerrainObjID#4134 scripts/server/player.cs (235): Unknown command damage. Object (4175) Player -> ShapeBase -> GameBase -> SceneObject -> NetObject -> SimObjectMy player.cs has the all the standard functions; onCollision, onImpact, damage, onDamage, onDiabled, etc.. They look just like the Full template build. I started from a Empty template and have added all the basic stuff from the Full template. Have I missed something?
Here's my scripts; gameCore.cs player.cs
#3
08/03/2013 (8:34 pm)
I'm looking for the same thing. How to go about and have the vehicle damaged by bullets and hitting objects.
#4
08/03/2013 (9:38 pm)
I figured why the damage wasn't being done. I wasn't exec the shapeBase.cs. So it seems that onImpact function works for players but for vehicles I get some errors about "getType" "getName".
#5
08/03/2013 (10:58 pm)
Here are the errors I'm getting when I'm in a vehicle and hit a StaticShape.scripts/server/vehicleWheeled.cs (61): Unable to find object: '0' attempting to call function 'getName' WheeledVehicleData::onImpact -> Car for just ran into ObjID#0 scripts/server/vehicleWheeled.cs (68): Unable to find object: '0' attempting to call function 'getType' scripts/server/vehicleWheeled.cs (72): Unable to find object: '0' attempting to call function 'getType'
#6
EDIT:
I was looking of my scripts and noticed that my WheeledVehicle didn't have damage, onDamage, onDestroyed functions. I also noticed that the vehicle datablock didn't have
08/04/2013 (1:11 pm)
I'm not sure what's going on. Why are these errors popping up?EDIT:
I was looking of my scripts and noticed that my WheeledVehicle didn't have damage, onDamage, onDestroyed functions. I also noticed that the vehicle datablock didn't have
// Object Impact Damage (uses DamageType::Impact)
collDamageThresholdVel = 23.0;
collDamageMultiplier = 0.02;So now I'm only getting these errors.scripts/server/vehicleWheeled.cs (68): Unable to find object: '0' attempting to call function 'getType' scripts/server/vehicleWheeled.cs (72): Unable to find object: '0' attempting to call function 'getType'Which calls
else if (%collidedObject.getType() & ($TypeMasks::TerrainObjectType | $TypeMasks::StaticShapeObjectType | $TypeMasks::InteriorObjectType)) else if (%collidedObject.getType() & ($TypeMasks::StaticTSObjectType))When I hit a staticshape object.
#7
EDIT.
I found out that my onDamage function was weird so I fixed that and now the health bar acts normally now. I just need to figure out how to disable the vehicle with the health bar reaches 0.
08/04/2013 (2:21 pm)
So I have a health bar to show the vehicle's health. The player spawns in as a vehicle. So when the player hits a staticshape the health bar goes down depending how fast but after that first hit the health bar does not move anymore. I also still get these errors in the console logscripts/server/vehicleWheeled.cs (68): Unable to find object: '0' attempting to call function 'getType' scripts/server/vehicleWheeled.cs (72): Unable to find object: '0' attempting to call function 'getType'I made sure that my vehicle datablock has "maxDamage and maxEnergy". I noticed that the when the vehicle hits the object it uses the energy first. How can I stop that?
EDIT.
I found out that my onDamage function was weird so I fixed that and now the health bar acts normally now. I just need to figure out how to disable the vehicle with the health bar reaches 0.
Torque Owner Lukas Joergensen
WinterLeaf Entertainment
This works for players:
function Armor::onImpact(%this, %obj, %collidedObject, %vec, %vecLen) { echo("c4Armor::onImpact -> "@ %this.getName() @" for "@ %obj.client.nameBase @" just ran into "@ %collidedObject.getName() @"ObjID#"@ %collidedObject); // believe it not but sometimes you can run into yourself ??? if (%obj == %collidedObject) %obj.damage(0, VectorAdd(%obj.getPosition(),%vec), %vecLen * %this.speedDamageScale, "ImpactNonPlayer"); // here we've impacted either the Terrain, a StaticShape, or an Interior else if (%collidedObject.getType() & ($TypeMasks::TerrainObjectType | $TypeMasks::StaticShapeObjectType | $TypeMasks::InteriorObjectType)) %obj.damage(0, VectorAdd(%obj.getPosition(),%vec), %vecLen * %this.speedDamageScale, "ImpactNonPlayer"); // here we've impacted with a TSStatic shape else if (%collidedObject.getType() & ($TypeMasks::StaticTSObjectType)) %obj.damage(0, VectorAdd(%obj.getPosition(),%vec), %vecLen * %this.speedDamageScale, "ImpactPlayer"); // we've just impacted another player else %obj.damage(0, VectorAdd(%obj.getPosition(),%vec), %vecLen * %this.speedDamageScale, "ImpactPlayer"); }See if it works for vehicles too. %vec is the impact direction %vecLen is the impact force.