I followed the code at this YouTube channel: https://www.youtube.com/watch?v=OR0e-1UBEOU&t=4178s, and did some modification on the code so that the scale of the bird will change during projectile using the absolute sine function under the if statement.
I'm using the scale (16/20)*|sin(distance)|
for my x and y component. However, when I launch the game, the scale stays as 0 along the path. Why is my scale staying as a constant zero?
using UnityEngine;
using UnityEngine.Assertions.Must;
using UnityEngine.SceneManagement;
public class Bird : MonoBehaviour
{
Vector3 OldPosition;
Vector3 DistanceDifference;
float TotalDistance = 0;
Vector3 _initialPosition;
private bool _birdWasLaunched;
[SerializeField] private float _launchPower = 500;
void start()
{
OldPosition = transform.position;
}
private void Awake()
{
_initialPosition = transform.position;
}
void Update()
{
if (_birdWasLaunched && GetComponent<Rigidbody2D>().velocity.magnitude > 0.1)
{
DistanceDifference = transform.position - OldPosition;
TotalDistance += DistanceDifference.magnitude;
OldPosition = transform.position;
transform.localScale = new Vector3((16/20)*Mathf.Abs(Mathf.Sin(TotalDistance/5)), (16/20)*Math.Abs(Mathf.Sin(TotalDistance /5)) , Mathf.Sin(TotalDistance /5));
}
if (transform.position.y > 15.00 || transform.position.y < -15.00 || transform.position.x > 18 || transform.position.x < -18)
{
string currentSceneName = SceneManager.GetActiveScene().name;
SceneManager.LoadScene(currentSceneName);
}
}
void OnMouseDown()
{
GetComponent<SpriteRenderer>().color = Color.red;
}
private void OnMouseUp()
{
GetComponent<SpriteRenderer>().color = Color.white;
Vector2 directionToInitialPosition = _initialPosition - transform.position;
GetComponent<Rigidbody2D>().AddForce(directionToInitialPosition * _launchPower);
GetComponent<Rigidbody2D>().gravityScale = 1;
_birdWasLaunched = true;
}
private void OnMouseDrag()
{
Vector3 newPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
transform.position = new Vector3(newPosition.x, newPosition.y);
}
}
(16/20)
is integer division, resulting in 0. Does replacing that with0.8
fix the issue? \$\endgroup\$