Unity How to create a procedural tube mesh [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I want to create a procedural mesh like you can see in the following picture:
Unfortunately I have no idea how to do that. Can anyone of you help me out?
I think I know how to create the mesh of the tube, but I do not know how to create those circles.

The following is a rough overview of how to edit the vertices of a mesh, but for more details this link might help you.
List<Vector3> vertices = new List<Vector3>();
List<int> triangles = new List<int>();
GenerateMesh(vertices, triangles);
Mesh mesh = gameObject.GetComponent<MeshFilter>().mesh;
mesh.vertices = vertices.ToArray();
mesh.triangles = triangles.ToArray();
In terms of actually generating your mesh, I would suggest generating N points in a circle on a plane, this is your start point. Then repeatedly move the plane forward slightly, rotate it, and generate more points. Each time connect the points to the previous set of points generated to make your triangles.

Related

How do I limit bouncing of physics objects [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm trying to implement a lot of poker chips using Unity.
But poker chips are moving like a spring.
I want to implement poker chip in real world using Unity physics.
I tried modifiying the value on Rigidbody (Mass, Drag, Angular Dag, etc.)
and also tried modifiying Physics Material.
But Those didn't work.
I want to remove bounce of poker chips.
Sorry for my bad english.
please help me.
Here is my link
https://www.youtube.com/watch?v=Lw02Jkpfw2I
and a poker chip prefab
enter image description here
Maybe your problem can be solved by adding a physics material.
Right click in the project hierachy and create a new Phsyic Material and set its values to something like this. I have named the object ZeroBounce.
Add the Physics Material to the colliders of your chips and your floor.
You should immediately see a better result.
If the above solution doesn't satisfy you you could also add a script that limits the velocity of the chips. It will slowly lower its vertical speed to zero if it is going up. This will result in a small bounce which I think is a bit more realistic. A damp value of 10 looks pretty smooth to me. You can also just straight up set the y velocity to zero like this: currentVelocity.y = 0; instead of the lerp method. Then you won't have any bounce at all.
public float damp;
void FixedUpdate(){
var currentVelocity = rigidbody.velocity;
if (currentVelocity.y <= 0f)
return;
currentVelocity.y = Mathf.Lerp(currentVelocity.y, 0, damp * Time.fixedDeltaTime);
rigidbody.velocity = currentVelocity;
}

How to move object based on rotation another [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I've got an issue in my VR project. I'm trying to move one object based on rotation of another one and first one should move only in kind of borders. I'm using a raycast to detect and control these objects. Both should go in x direction.
1 - Object that I rotate
2 - Object that should move
Any tips? Thanks in advance!
Well this looks like a lathe so I asume that you want to move the tool post over one axis when rotating the wheel.
You want to "link" them, so what I would do is rotate the wheel using a method that also moves the tool post.
Try this:
public float ratio = 1.0f;
public GameObject wheel;
public GameObject tool;
public void RotateWheel(float amount)
{
wheel.transform.Rotate(Vector3.forward * amount);
tool.transform.Translate(Vector3.left * amount * ratio);
}
Note the following:
Amount is passed as degrees.
Ratio is the ratio between wheel
rotation and tool translation. At 1, for each degree, the tool moves
1 unit. Adjust it at your will. I assumed the orientation of your
moving parts based on the model. Try changing the vector directions if they do not work as expected.

Randomly generating obstacles in Unity [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Currently I'm creating game in which whole level is generated when player moves. I have working script for that, but now I want to generate obstacles in front of the player. My idea is to add empty object to my terrain segment(these are dynamically generated) and then instantiate random obstacles at their position at runtime. The only thing i don't know is how this script should pick random empty object(empty object is child of the segment) to instantiate this obstacle? The script which generates level is attached to player.
This gives you an idea of how to do it.
Spawns a random game object to one of the empty gameobjects around your terrain.
//Add the random objects in the inspector
public List<GameObject> gameObjects;
//Spawn points around the terrain
public List<Transform> emptyTransforms;
foreach(var item in emptyTransforms){
var objToSpawn = gameObjects[Random.Range(0, gameObjects.Length)];
var objSpawned = Instantiate(objToSpawn, emptyTransforms[Random.Range(0, emptyTransforms.Length)].position, Quaternion.identity);
objSpawned.transform.SetParent(newParent);
}
Use the Random.Range function to calculate random values. Then make the values within bounds of where you want obstacles to spawn and create a Vector3 with those values. Now the obstacles are spawned in a random area.
If you have a fixed list of possible positions, just store them in a public variable in the script. If your empty gameobjects are the positions, create a public GameObject[] positions;, populate it and use something like Random.Range to pick one of it.
Also I suggest you have a look at item pooling and don't instantiate new objects all the time (and probably destroy "old" ones). That is better for your performance.

Move line until it hits a collection of points [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have an imaginary line segment (I have the start and end of the segment) and a List of Points. I want to move this line closer to the collection of points until it hits one of them. This image should make things clearer:
In this image I want to move the green line to the red points until it hits them and get the blue line.
So I have Point startGreen, endGreen; and List<Point> redPoints. How can I get Point startBlue, endBlue;?
Follow these steps:
Calculate distance between each point and the green line
find minimum distance
move green line to the point with minimal distance
-- OR --
Find a coordiante transformation which rotates the green line to (say) the y-axis.
Transform all points
find the point with the largest x-component
Move the green line to this point.
Do the inverse trsnafomation

Get xyz coordinates from starting point, quaternion and moved distance [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
In my case I have a starting coordinate x,y,z, an orientation in Quaternion and I know the moved distance.
Basically I would like to know the x',y',z' after applying the transformation and the forward movement. So I am trying to move a point in 3D using quaternion. I guess it should be just a simple calculation but for some reason I cannot find the solution that easily.
In previously I converted the Quaternion to Euler angles and used them to calculate the x',y',z'. Unfortunately because of the Gimbal lock this solution is not suitable for me anymore.
I have found a few example for example this one in python and here's an other in C#, but I still did not get the formula of them as they are discussing the rotation instead of the movement it self, the C# example just changes the middle point of the cube and then it redraws it with the rotation.
Why reinvent the wheel ? This kind of operation is best handled via matrixes - and C# has even support for it.
// PresentationCore.dll
using System.Windows.Media.Media3D;
Matrix3D matrix = Matrix3D.Identity;
matrix.Translate(new Vector3D(x, y, z));
matrix.Rotate(quaterion);
var newPoint = matrix.Transform(point);

Categories