Add get_linear_velocity() method to VehicleBody class
Doc added also.
This commit is contained in:
parent
436debb045
commit
97da9f14ab
@ -41501,6 +41501,20 @@ This method controls whether the position between two cached points is interpola
|
|||||||
<description>
|
<description>
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="get_linear_velocity" qualifiers="const">
|
||||||
|
<return type="Vector3">
|
||||||
|
</return>
|
||||||
|
<description>
|
||||||
|
Returns the vehicle body speed or velocity in a 3D vector, to get the speed in scalar value
|
||||||
|
get the length of the return vector, the scalar value is in Godot units/seconds, if you
|
||||||
|
assume 1.0 is a meter, then it is in meters/sec
|
||||||
|
Example:
|
||||||
|
# vehicle is an instance of VehicleBody, 1.0 asumed as 1 meter:
|
||||||
|
var speed_ms = vehicle.get_linear_velocity().length()
|
||||||
|
# Lets convert it to Km/h:
|
||||||
|
var speed_kms = speed_ms * 3.6
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
</methods>
|
</methods>
|
||||||
<constants>
|
<constants>
|
||||||
</constants>
|
</constants>
|
||||||
|
@ -936,7 +936,7 @@ void VehicleBody::_direct_state_changed(Object *p_state) {
|
|||||||
wheel.m_deltaRotation *= real_t(0.99);//damping of rotation when not in contact
|
wheel.m_deltaRotation *= real_t(0.99);//damping of rotation when not in contact
|
||||||
|
|
||||||
}
|
}
|
||||||
|
linear_velocity = s->get_linear_velocity();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VehicleBody::set_mass(real_t p_mass) {
|
void VehicleBody::set_mass(real_t p_mass) {
|
||||||
@ -990,6 +990,10 @@ float VehicleBody::get_steering() const{
|
|||||||
return m_steeringValue;
|
return m_steeringValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector3 VehicleBody::get_linear_velocity()
|
||||||
|
{
|
||||||
|
return linear_velocity;
|
||||||
|
}
|
||||||
|
|
||||||
void VehicleBody::_bind_methods(){
|
void VehicleBody::_bind_methods(){
|
||||||
|
|
||||||
@ -1008,6 +1012,8 @@ void VehicleBody::_bind_methods(){
|
|||||||
ObjectTypeDB::bind_method(_MD("set_steering","steering"),&VehicleBody::set_steering);
|
ObjectTypeDB::bind_method(_MD("set_steering","steering"),&VehicleBody::set_steering);
|
||||||
ObjectTypeDB::bind_method(_MD("get_steering"),&VehicleBody::get_steering);
|
ObjectTypeDB::bind_method(_MD("get_steering"),&VehicleBody::get_steering);
|
||||||
|
|
||||||
|
ObjectTypeDB::bind_method(_MD("get_linear_velocity"),&VehicleBody::get_linear_velocity);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("_direct_state_changed"),&VehicleBody::_direct_state_changed);
|
ObjectTypeDB::bind_method(_MD("_direct_state_changed"),&VehicleBody::_direct_state_changed);
|
||||||
|
|
||||||
ADD_PROPERTY( PropertyInfo(Variant::REAL,"motion/engine_force",PROPERTY_HINT_RANGE,"0.00,1024.0,0.01"),_SCS("set_engine_force"),_SCS("get_engine_force"));
|
ADD_PROPERTY( PropertyInfo(Variant::REAL,"motion/engine_force",PROPERTY_HINT_RANGE,"0.00,1024.0,0.01"),_SCS("set_engine_force"),_SCS("get_engine_force"));
|
||||||
|
@ -178,6 +178,7 @@ public:
|
|||||||
void set_steering(float p_steering);
|
void set_steering(float p_steering);
|
||||||
float get_steering() const;
|
float get_steering() const;
|
||||||
|
|
||||||
|
Vector3 get_linear_velocity();
|
||||||
|
|
||||||
VehicleBody();
|
VehicleBody();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user