- Home /
Would i need Time.deltaTime if am just incrementing transform.position
//this function would set the ScaleToLeft function, when this object size is not less than the referenceSize variable
private void ResetScaleToLeft()
{
//Calls teh scale rate function that sets the scale rate value
SetScaleRate();
//holds teh size of the object before its scaled
previousSize = this.GetComponent<SpriteRenderer>().bounds.size.x;
//Reset Scale of the object
transform.localScale = new Vector3(RoundUpResetValue(), transform.localScale.y, transform.localScale.z);
//holds the new Size of the object after its scaled
newSize = this.GetComponent<SpriteRenderer>().bounds.size.x;
//Calls this functions
NewObjectPositionToLeft();
}
//this fucntion would set the new X position to the left
private void NewObjectPositionToLeft()
{
float offset;
float newSizeDifference;
float previousSizeDifference;
//Calculating the new Size difference
newSizeDifference = (newSize - originalSize) / 2;
//Calculatig the previous Size difference
previousSizeDifference = (previousSize - originalSize) / 2;
//Calcuates the difference between the new size difference and previous size difference
offset = newSizeDifference - previousSizeDifference;
transform.position = new Vector3(transform.position.x - offset , transform.position.y, transform.position.z);
}
Answer by tuinal · Jul 09, 2020 at 01:04 AM
The reason to multiply by delta time is if you're updating per frame; if you don't, then the rate the object moves at will vary with framerate, which is bad/inconsistent behaviour.
If you're not updating per-frame (impossible to tell from the code when the methods are called), but in response to an event (e.g. moving something instantly 4 units left when clicked), then you don't need to multiply by delta time.
Thank you very much for your reply,
Am sorry that my code isn't very readable , i would work on that. The ResetScaleToLeft() is called from the Update Function when a boolean variable = true. When the ResetScalToLeft() function is done executing , it then calls the NewObjectPositionToLeft(). The NewObjectPositionToLeft() function is where an using transform.position.