void Start() { DVector2 vec = new DVector2((DReal)transform.position.z, (DReal)transform.position.x); DReal rotation = DReal.Radians((DReal)transform.rotation.eulerAngles.y); /*Entity ent =*/ ComSat.Spawn(entityName, team, vec, rotation); //if(ent == null) return; //if(action == Action.MOVE) { // ComSat.IssueMove(ent, new DVector2((DReal)point.x, (DReal)point.y)); //} if (team == ComSat.localTeam) { FindObjectOfType <CameraController>().LookAt(vec); } }
// This could be smarter. If dest is too close & perpendicular, then the tank // can end up circling around. public void MoveTowards(DVector2 dest) { ComSat.Trace(this, "MoveTowards"); var dir = dest - entity.position; // also vector to dest. var targetAngle = DVector2.ToAngle(dir); var baseAngle = Utility.CalculateNewAngle(entity.rotation, targetAngle, DReal.Radians(turnSpeed)); entity.rotation = baseAngle; // Move along current heading. Ramp speed up as the angle gets closer. // Augh. // [-pi,pi] => [0,2pi] if (targetAngle < 0) { targetAngle += DReal.TwoPI; } // Get targetAngle within +/- pi of baseAngle. if (targetAngle < baseAngle - DReal.PI) { targetAngle += DReal.TwoPI; } else if (targetAngle > baseAngle + DReal.PI) { targetAngle -= DReal.TwoPI; } var diff = DReal.Abs(baseAngle - targetAngle); if (canMoveWithoutTurning || diff < maxMoveAngle) { var distance = dir.magnitude; //print("Distance: " + distance + " speed is: " + tickSpeed); var speed = minSpeed + (maxSpeed - minSpeed) * (1 - (diff / DReal.PI)); if (distance < speed) { speed = DReal.Max(minSpeed, distance); } entity.velocity = canMoveWithoutTurning ? dir.normalized * speed : DVector2.FromAngle(baseAngle) * speed; } else { Stop(); } }
void TurnTurret(DReal targetAngle) { turretRotation = Utility.CalculateNewAngle(turretRotation, targetAngle, DReal.Radians(turretTurnSpeed)); }
void TickUpdate() { ComSat.Trace(this, "TickUpdate"); if (ComSat.EntityExists(target)) { var dir = target.position - entity.position; // also vector to dest. var targetAngle = DVector2.ToAngle(dir); var baseAngle = Utility.CalculateNewAngle(entity.rotation, targetAngle, DReal.Radians(turnSpeed)); entity.rotation = baseAngle; } entity.velocity = DVector2.FromAngle(entity.rotation) * speed; DVector2 newPosition = entity.position + entity.velocity * ComSat.tickRate; // FIXME: this should do something to account for hitting fast-moving projectiles. DVector2 hitPosition; Entity hit = ComSat.LineCast(entity.position, newPosition, out hitPosition, entity.team); if (hit != null && (!hit.hitOnlyIfTargetted || hit == target)) { hit.Damage((int)ComputeDamage()); var position = new Vector3((float)hitPosition.y, 0, (float)hitPosition.x); var rotation = Quaternion.AngleAxis((float)entity.rotation, Vector3.up); if (impactPrefab != null && ComSat.RateLimit()) { ObjectPool.Instantiate(impactPrefab, position, rotation); } //if(trail) { // trail.transform.parent = null; // trail.autodestruct = true; // trail = null; //} if (!penetrates || speed < minPenetrationSpeed) { ComSat.DestroyEntity(entity, DestroyReason.HitTarget); return; } else { speed -= penetrationSpeedReduction; } } }