using System;
using System.Collections;
using System.Collections.Generic;
using Unigine;
[Component(PropertyGuid = "ca695c8787d5703a22a6c2516a3c177cddf38cab")]
public class TheVehicle : Component
{
, , . , .
[ShowInEditor][Parameter(Tooltip = "Left Wheel")]
private Node targetWheelL = null;
[ShowInEditor][Parameter(Tooltip = "Right Wheel")]
private Node targetWheelR = null;
[ShowInEditor][Parameter(Tooltip = "Left Wheel F")]
private Node targetFWL = null;
[ShowInEditor][Parameter(Tooltip = "Right Wheel F")]
private Node targetFWR = null;
[ShowInEditor][Parameter(Tooltip = "theCar")]
private Node targetCar = null;
. tooltip , .
private JointWheel my_jointL;
private JointWheel my_jointR;
private JointWheel my_jointFL;
private JointWheel my_jointFR;
.
Controls controls = null;
float angle = 0.0f;
float velocity = 0.0f;
float torque = 0.0f;
private float ifps;
.
private void Init()
{
my_jointL = targetWheelL.ObjectBodyRigid.GetJoint(0) as JointWheel;
my_jointR = targetWheelR.ObjectBodyRigid.GetJoint(0) as JointWheel;
my_jointFL = targetFWL.ObjectBodyRigid.GetJoint(0) as JointWheel;
my_jointFR = targetFWR.ObjectBodyRigid.GetJoint(0) as JointWheel;
, JointWheel.
, , ( ).
PlayerPersecutor player = new PlayerPersecutor();
controls = player.Controls;
}
, PlayerPresecutor, Controls player .
private void Update()
{
ifps = Game.IFps;
if ((controls.GetState(Controls.STATE_FORWARD) == 1) || (controls.GetState(Controls.STATE_TURN_UP) == 1))
{
velocity = MathLib.Max(velocity, 0.0f);
velocity += ifps * 50.0f;
torque = 5.0f;
}
else if ((controls.GetState(Controls.STATE_BACKWARD) == 1) || (controls.GetState(Controls.STATE_TURN_DOWN) == 1))
{
velocity = MathLib.Min(velocity, 0.0f);
velocity -= ifps * 50.0f;
torque = 5.0f;
}
else
{
velocity *= MathLib.Exp(-ifps);
}
velocity = MathLib.Clamp(velocity, -90.0f, 90.0f);
if ((controls.GetState(Controls.STATE_MOVE_LEFT) == 1) || (controls.GetState(Controls.STATE_TURN_LEFT) == 1))
angle += ifps * 100.0f;
else if ((controls.GetState(Controls.STATE_MOVE_RIGHT) == 1) || (controls.GetState(Controls.STATE_TURN_RIGHT) == 1))
angle -= ifps * 100.0f;
else
{
if (MathLib.Abs(angle) < 0.25f) angle = 0.0f;
else angle -= MathLib.Sign(angle) * ifps * 45.0f;
}
angle = MathLib.Clamp(angle, -10.0f, 10.0f);
float base_a = 3.3f;
float width = 3.0f;
float angle_0 = angle;
float angle_1 = angle;
if (MathLib.Abs(angle) > MathLib.EPSILON)
{
float radius = base_a / MathLib.Tan(angle * MathLib.DEG2RAD);
angle_0 = MathLib.Atan(base_a / (radius + width / 2.0f)) * MathLib.RAD2DEG;
angle_1 = MathLib.Atan(base_a / (radius - width / 2.0f)) * MathLib.RAD2DEG;
}
Update, , .
my_jointFL.Axis10 = MathLib.RotateZ(angle_0).GetColumn3(0);
my_jointFR.Axis10 = MathLib.RotateZ(angle_1).GetColumn3(0);
if (controls.GetState(Controls.STATE_USE) == 1)
{
velocity = 0.0f;
my_jointL.AngularDamping = 20000.0f;
my_jointR.AngularDamping = 20000.0f;
my_jointFL.AngularDamping = 20000.0f;
my_jointFR.AngularDamping = 20000.0f;
}
else
{
my_jointL.AngularDamping = 0.0f;
my_jointR.AngularDamping = 0.0f;
my_jointFL.AngularDamping = 0.0f;
my_jointFR.AngularDamping = 0.0f;
}
, , . , 4 . , , 10 .
if (Input.IsKeyDown(Input.KEY.Q))
{
targetCar.ObjectBodyRigid.AddLinearImpulse(vec3.UP*1000f);
}
if (Input.IsKeyDown(Input.KEY.E))
{
targetCar.ObjectBodyRigid.AddLinearImpulse(vec3.DOWN*1000f);
}
}
Update , . , тАФ ┬лthis.┬╗ .
private void UpdatePhysics()
{
my_jointL.AngularVelocity = velocity;
my_jointR.AngularVelocity = velocity;
my_jointL.AngularTorque = torque;
my_jointR.AngularTorque = torque;
}
}
Update Physics , velocity torque.