2 Origonal Author: ECHibiki
4 Moves the ball across the terrain
8 using System
.Collections
;
9 using System
.Collections
.Generic
;
12 public class StationNav
: StationAbstract
{
14 public static float torqueOffset
= 0.0f
;
16 private GameObject yarn_object
;
17 private StationGeneric generic_station
;
18 private Rigidbody2D yarn_rigidbody
;
20 public float yarn_mass
, linear_drag
, angular_drag
, gravity_effect
;
21 public RigidbodyType2D body_type
;
22 public bool simulated
;
24 public float accel_torque_magnitude_applied
;
25 public float brake_torque_magnitude_applied
;
26 public float accel_force_magnitude_aplied
;
27 public float brake_force_magnitude_aplied
;
28 public float max_angular_velocity
;
29 public Vector2 max_linear_velocity
;
31 public float dragScale
; // for momentum
34 //handled by generic_station
35 yarn_object
= GameObject
.FindGameObjectWithTag("YarnPhysics") as GameObject
;
36 generic_station
= gameObject
.AddComponent (typeof(StationGeneric
)) as StationGeneric
;
37 generic_station
.startRoutine (this);
39 yarn_rigidbody
= yarn_object
.GetComponent
<Rigidbody2D
> ();
41 yarn_rigidbody
.bodyType
= body_type
;
42 yarn_rigidbody
.simulated
= simulated
;
43 yarn_rigidbody
.mass
= yarn_mass
;
44 yarn_rigidbody
.drag
= linear_drag
;
45 yarn_rigidbody
.angularDrag
= angular_drag
;
46 yarn_rigidbody
.gravityScale
= gravity_effect
;
50 public override bool actionPressed(){
51 //handled by generic_station
52 return generic_station
.actionPressed ();
55 public override void fire1Pressed()
59 public override void fire2Pressed()
63 public override void fire3Pressed()
67 public override bool checkDistance (Vector2 caller_location
, StationAbstract station
){
68 return generic_station
.checkDistance (caller_location
, station
);
71 public override bool IsOccupied(Vector2 caller_location
, StationAbstract station
)
73 return generic_station
.IsOccupied(caller_location
, station
);
76 public override void directionPressed(Vector3 dir_vec
){
77 //make it a torque magn
78 float torque
= -dir_vec
.x
;
81 torque
*= (1 + torqueOffset
);
82 //momentum: when yarn is going up, apply a "down" drag force
84 if (yarn_rigidbody
.velocity
.y
> 0) {
85 yarn_rigidbody
.AddForce (Vector2
.down
* dragScale
);
87 if (Mathf
.Abs (dir_vec
.x
) > 0) {
88 if (Mathf
.Sign (-yarn_rigidbody
.velocity
.x
) != Mathf
.Sign (torque
)) {
89 yarn_rigidbody
.AddTorque (Mathf
.Sign(torque
) * brake_torque_magnitude_applied
);
90 yarn_rigidbody
.AddForce (new Vector2(-Mathf
.Sign(yarn_rigidbody
.velocity
.x
) * brake_force_magnitude_aplied
, 0 ));
91 // Debug.Log ("Braking");
93 yarn_rigidbody
.AddTorque (Mathf
.Sign(torque
) * accel_torque_magnitude_applied
);
94 yarn_rigidbody
.AddForce (new Vector2(Mathf
.Sign(yarn_rigidbody
.velocity
.x
)* accel_force_magnitude_aplied
, 0));
98 if (Mathf
.Abs(yarn_rigidbody
.angularVelocity
) > max_angular_velocity
)
99 yarn_rigidbody
.angularVelocity
= Mathf
.Sign(yarn_rigidbody
.angularVelocity
) * max_angular_velocity
;
100 if (Mathf
.Abs(yarn_rigidbody
.velocity
.x
) > max_linear_velocity
.x
)
101 yarn_rigidbody
.velocity
= new Vector2(Mathf
.Sign(yarn_rigidbody
.velocity
.x
) * max_linear_velocity
.x
, yarn_rigidbody
.velocity
.y
);
102 if (Mathf
.Abs(yarn_rigidbody
.velocity
.y
) > max_linear_velocity
.y
)
103 yarn_rigidbody
.velocity
= new Vector2(yarn_rigidbody
.velocity
.x
, Mathf
.Sign(yarn_rigidbody
.velocity
.y
) * max_linear_velocity
.y
);
104 // Debug.Log(yarn_rigidbody.velocity);
105 // Debug.Log (max_linear_velocity.x);
108 protected override void enterStation(){
109 //handled by generic_station
112 protected override void exitStation(){
113 //handled by generic_station
116 public void UpgradeTorque(float offset
)
118 torqueOffset
+= offset
;