Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink
Share
Go down
Member [Lv. 0]
Member [Lv. 0]
Posts : 1
Points : 26
Rep : 0
Join date : 2018-06-27
View user profile

How can I make an elastic object in Unity?

on Wed Jun 27, 2018 7:07 pm
Hello, I'm new in Unity and need some help, would greatly appreciate any answers!

I'm trying to create an elastic plane, which I want to stretch by dragging. I want to stretch the whole plane by the x-axis using ctrl+left mouse button and by the y-axis using alt+left mouse button. Then I want to stretch single polygons which are along the border of the plane by using just the left mouse button and dragging in any direction.
So far I've managed to stretch the whole plane with either left or right mouse button, using the script beneath, but I haven't been able to limit how far it can be stretched so I would appreciate any tips on how to do that as well. For stretching single polygons I've looked into the cloth modifier and tried to attach movable objects, but haven't been able to make it work at all. Thank you for any help!

{

public GameObject elasticobject;
public float sizingFactor = 0.1f;
private GameObject lastSpawn = null;
private float startSize;
private float startX;

void Update()
{

   if (Input.GetMouseButton(0))
   {
       Vector3 size = elasticobject.transform.localScale;
       size.x = startSize + (Input.mousePosition.x - startX) * sizingFactor;
       elasticobject.transform.localScale = size;
   }

   if (Input.GetMouseButton(1))
   {
       Vector3 size = elasticobject.transform.localScale;
       size.y = startSize + (Input.mousePosition.y - startX) * sizingFactor;
       elasticobject.transform.localScale = size;
   }
}
}
Back to top
Permissions in this forum:
You cannot reply to topics in this forum