public TransformExt() { position = new Vector3(0, 0, 0); rotation = Quaternion.identity; scale = new Vector3(1, 1, 1); posLHS = position; worldMatrix = Matrix4x4.identity; }
public TransformExt(Spatial spatial) { position = Vector3.FromV3(spatial.GetTranslation()); rotation = Quaternion.FromEulerRHS(Vector3.FromV3((spatial.GetRotationDegrees()))); scale = Vector3.FromV3(spatial.GetScale()); posLHS = new Vector3(position.x, position.y, -position.z); updateTransformMatrix(); }
public void RotateAround(Vector3 point, Vector3 axis, float angle) { float distance = (position - point).magnitude; Vector3 direction = (position - point).normalized; Quaternion rotate = Quaternion.AngleAxis(angle, axis); direction = rotate * direction; position = point + direction * distance; }
public static TransformExt FromTransform(Transform transform, Vector3 rotation) { TransformExt transformExt = new TransformExt(); transformExt.worldMatrix = Matrix4x4.TransformToMatrix4x4(transform); transformExt.position = Vector3.FromV3(transform.origin); transformExt.rotation = Quaternion.FromEuler(rotation); transformExt.scale = new Vector3(1, 1, 1); return(transformExt); }
public void Revive() { transform.position = startPos; transform.rotation = Quaternion.identity; velocity = Vector3.zero; acceleration = Vector3.zero; dead = false; time = 0; index = 0; fitness = 0; }
private void HandleCollisions() { for (int i = 0; i < rockets.Length; i++) { Vector3 rocketPos = rockets[i].transform.position; bool kill = false; for (int j = 0; j < obstacles.Length; j++) { Vector3 obstaclePos = obstacles[j].transform.position; float obstacleSize = obstacles[j].transform.scale.x; if ((rocketPos - obstaclePos).magnitude < obstacleSize && rockets[i].isDead() == false) { rockets[i].SetToPunish(timeThisGeneration); kill = true; } } Vector3 targetPos = target.transform.position; float targetSize = target.transform.scale.x; if ((rocketPos - targetPos).magnitude < targetSize && rockets[i].isDead() == false) { rockets[i].SetToReward(timeThisGeneration); kill = true; targetHits++; } if ((rocketPos.y > References.northWall || rocketPos.y < References.southWall || rocketPos.x > References.eastWall || rocketPos.x < References.westWall) && rockets[i].isDead() == false) { rockets[i].SetToPunish(timeThisGeneration); kill = true; } if (kill == true) { rockets[i].Kill(); } } }
public override void _Ready() { transform = new TransformExt(); startPos = new Vector3(0, References.rocketStartHeight, 0); transform.position = startPos; transform.rotation = Quaternion.identity; transform.scale = Vector3.one * References.rocketScale; exhaust = (Particles)GetChild(1); velocity = Vector3.zero; currentThrust = 0; thrustPercentage = 0; maxExhaustSpeed = 20; maxExhaustTTL = 1f; instructions = new Instruction[References.instructionSize]; for (int i = 0; i < References.instructionSize; i++) { instructions[i] = new Instruction(); } }
void updateTransformMatrix(Vector3 LHS) { worldMatrix = Matrix4x4.translationMatrix(LHS) * Matrix4x4.scaleMatrix(scale) * Matrix4x4.rotationMatrix(rotation); }
private void AddForce(Vector3 force) { acceleration = force / References.rocketMass; velocity += acceleration; acceleration = Vector3.zero; }
public void Kill() { velocity = Vector3.zero; dead = true; }