I’m having issues properly scaling object in my game. Specifically, I’m trying to scale my player to a certain amount when he or she collides with certain objects. For example, colliding into a ball will cause the player to scale down to half its normal size; meanwhile, colliding into a square will scale the player to twice its size.
As of right now, I’ve set up a single function to scale the player based on a value other objects set as one of the function’s parameters. When I first made the function, I initially mistook the magnitude to be a single value from the Vector3 I need to create inside the function. Here is the function in full:
//*used in other scripts
//changes player's scale based on amount used for each player
public void AlterPlayerScale(float scaleValue, float initMagnitude, float scalingDuration){
//set scaling amount for scaling player
Vector3 newScale = new Vector3(initMagnitude+scaleValue,
initMagnitude+scaleValue,
initMagnitude+scaleValue);
Debug.Log ("new Scale: "+ newScale);
//scaling step
scaleStep += Time.deltaTime/scalingDuration;
Debug.Log ("player's scale: " + transform.localScale.x);
//alter player's scale
transform.localScale = Vector3.Lerp(transform.localScale,
newScale,
scaleStep);
}
I have two objects that alter the player’s scale: a collectable, which should increase the player’s scale; and a enemy, which decreases the player’s scale. Both objects have scripts referencing the function above via OnTriggerEnter() or OnCollisionEnter(), respectively: when the objects collides with the player, the object finds the player’s current local scale magnitude to compare with in the AlterPlayerScale() function above.
However, an issue occurs when the player collides with an enemy after colliding with a collectable: the vector the enemy calculates causes the function to create a positive vector.
I’ve thought of just using one of the three coordinates from a minimum player scale I’ve set up in another script to use for the ‘initMagnitude’ variable instead. However, the vector that comes out as a result will not be relative to the player’s current scale.
As of right now, I still need help scaling the player down properly even after colliding with a collectable. If my description of the problem was confusing, please let me know so I may clarify the problem ASAP.