public override void DefaultBehavior() { float d = Vector3.Distance(transform.position, _pathAi.target); if (d < stoppingDistance) { _pathAi.setNextNode(); } if (_pathAi.target != Vector3.zero) { /* * transform.LookAt(_pathAi.target); * var angles = transform.rotation.eulerAngles; * transform.rotation=Quaternion.Euler(0,angles.y,0); */ //rb.velocity = transform.forward * speed; Vector2 inp = new Vector2(0, 1); //step on gas for now //curVelo += accel; //step on da gas (TODO: add braking and stuff later) //steer towards next node float angle = Vector3.SignedAngle(_pathAi.target - transform.position, transform.forward, Vector3.up); //find direction to steer in if (angle > aiTurnThreshold) { inp.x = -1; } else if (angle < -aiTurnThreshold) { inp.x = 1; } driverInput = inp; /* * Vector3 twist = Vector3.Project(transform.up,Vector3.up); * float mag = twist.y; * * if (mag < 0.5) { * inp = Vector2.zero; * } */ } else { //rb.velocity=Vector3.zero; } }
public override void DefaultBehavior() { float d = Vector3.Distance(transform.position, _pathAi.target); if (d < stoppingDistance) { _pathAi.setNextNode(); } if (_pathAi.target != Vector3.zero) { anim.SetBool("moving", true); transform.LookAt(_pathAi.target); var angles = transform.rotation.eulerAngles; transform.rotation = Quaternion.Euler(0, angles.y, 0); transform.position += transform.forward * speed * Time.deltaTime; } else { anim.SetBool("moving", false); } }