- Home /
scale a cylinder from one side only
i have a cylinder shaped like a rod as in the pic which i need to scale from only on of its side .i tried adding half of its increased scale to its position but i am not able to achieve it.i just need to increase its size lengthwise from one side and cancel increase from the other .i am using the current logic but it does not work:-
function Update()
{
if(Input.GetButtonDown("Fire1"))
{
transform.localScale.y+=1;
transform.position.x = transform.position.y + transform.localScale.y/2;
}
}
please help!
cylinder.jpg
(66.2 kB)
Comment
Answer by Cherno · May 10, 2015 at 08:07 PM
initialLength is just the actual length of of cylinder, and transform.forward might have to be substituted with another direction depending on the cylinder's pivot orientation.
var initialLength : int = 2;
var currentLength : int = 2;
function Update() {
transform.localScale.y+=1;
currentLength += 1;
transform.position = transform.position + transform.forward * ((currentLength - 1) / 2);
}
nope ur code is malfunctioning and sending it zoo$$anonymous$$g upwards with high position change
Answer by nieyoub23 · Nov 08, 2017 at 05:13 PM
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class fluidScale : MonoBehaviour {
/*Changing the scale of the z axis while changing the position along the z axis,
* giving the visual effect that the fluid is moving in one direction. Doing it
* this way because Unity scales in two directions, not one.*/
public GameObject FluSph;
//I used 0,0,0.5
public Vector3 ExpandZ;
//0,0,0.25
public Vector3 MoveZ;
// Update is called once per frame
void Update () {
//makes the cube scale bigger on the Z axis
FluSph.transform.localScale += ExpandZ;
//transforms the position of the cube to make it appear that it is only expanding on one side
FluSph.transform.position+=MoveZ;
}
}