- Home /
How to scale a object after moving the same gameobject?
Hi, does anyone know how to scale a object after moving the same gameobject. Currently im using touchscript which is found from the asset store and i only could scale and move the object at a separate time. Heres the current code:
protected override float doScaling(Vector2 oldScreenPos1, Vector2 oldScreenPos2, Vector2
newScreenPos1,
Vector2 newScreenPos2, ProjectionParams projectionParams)
{
var newVector = projectionParams.ProjectTo(newScreenPos2, TransformPlane) -
projectionParams.ProjectTo(newScreenPos1, TransformPlane);
var oldVector = projectionParams.ProjectTo(oldScreenPos2, TransformPlane) -
projectionParams.ProjectTo(oldScreenPos1, TransformPlane);
return newVector.magnitude / oldVector.magnitude;
}
/// <inheritdoc />
protected override Vector3 doOnePointTranslation(Vector2 oldScreenPos, Vector2 newScreenPos,
ProjectionParams projectionParams)
{
if (isTransforming)
{
return projectionParams.ProjectTo(newScreenPos, TransformPlane) -
projectionParams.ProjectTo(oldScreenPos, TransformPlane);
}
screenPixelTranslationBuffer += newScreenPos - oldScreenPos;
if (screenPixelTranslationBuffer.sqrMagnitude > screenTransformPixelThresholdSquared)
{
isTransforming = true;
return projectionParams.ProjectTo(newScreenPos, TransformPlane) -
projectionParams.ProjectTo(newScreenPos - screenPixelTranslationBuffer, TransformPlane);
}
return Vector3.zero;
}
/// <inheritdoc />
protected override Vector3 doTwoPointTranslation(Vector2 oldScreenPos1, Vector2 oldScreenPos2,
Vector2 newScreenPos1, Vector2 newScreenPos2, float dR, float dS, ProjectionParams projectionParams)
{
if (isTransforming)
{
return projectionParams.ProjectTo(newScreenPos1, TransformPlane) - projectScaledRotated(oldScreenPos1, dR, dS, projectionParams);
}
screenPixelTranslationBuffer += newScreenPos1 - oldScreenPos1;
if (screenPixelTranslationBuffer.sqrMagnitude > screenTransformPixelThresholdSquared)
{
isTransforming = true;
return projectionParams.ProjectTo(newScreenPos1, TransformPlane) -
projectScaledRotated(newScreenPos1 - screenPixelTranslationBuffer, dR, dS, projectionParams);
}
//doScaling();
return Vector3.zero;
}
Answer by KittenSnipes · Jan 29, 2018 at 03:43 AM
I think Unity has a script you can import automatically when you right click in your project panel and the package is called 'CrossPlatform Input'. I like free and easily accessible stuff. Why do you not make it easy on yourself and just access the transforms localScale and use Vector3.Lerp to shrink it and just use the move script in the same function. A good function is void Update().
oh, i was using that as it came with touchscript and i was just wondering if i could just modify the code slightly.
So are you just scaling a regular gameobject while it moves?
Currently yes and sry if i have word it wrongly but i would like to scale the object after i have move the object.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Character not moving? 1 Answer
How does Mathf.SmoothDamp's max speed work? 1 Answer
Complex object scaling 0 Answers