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
I am fairly new to Unity and am building an endless runner in Unity 3d off this tutorial: http://catlikecoding.com/unity/tutorials/runner/
I have followed the tutorial verbatim and have tried several approaches but can't increase the gravity in game - right now I have the block moving and jumping, but no matter what vectors I apply in the jump or any other variable I change the block does not "jump up" and come back down "quickly" or like most endless runners.
The gravity is too little - my cube floats in the air a while before coming down.
I am trying to achieve a gravity affect like in Jetpack Joyride; a normal strength of gravity. Gravity is checked on my Runner object and It seems as though Unity's gravity is "fixed" at a low strength.
I have tried going to Input Settings and increasing gravity from 1000 up, I have tried altering Vector of jump.
I have increased mass of the Runner object. Nothing affects gravity.
How can I increase gravity in Unity?
If you want to access the global gravity in a unity game, you can access it through Physics.gravity. You can either set it to a new vector3 or you can multiply it by a factor.
Examples:
Physics.gravity = new Vector3(0, 10, 0)
or
Physics.gravity *= 3;
If you go to the menu Edit> Project Settings> Physics, you can alter the global gravity of your project.
However, falling slowly USUALLY means that the scale of your models are wrong. for example, typically 1 unit in unity is 1 m. But if your model is 100x100 units, then that means it's 100m tall. Say it jumps 3x the height of itself, then it has to fall 300m. a fall from 300m would take a hell of a long time at earth's gravity compared to something like 2m.
So: 1) make sure your gravity is set to something reasonable, and 2) make sure things are in the correct scale. A humanoid character should be somewhere in the range of 2 units (2m ~= 6 feet).
Related
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;
}
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
so, a little backstory. I have been working on a cel shaded 3d rpg for a while now. it' s going to have the options to switch between action based and turn based. that's for a later time though.
the question I have is I want to add a way to damage the enemy when the sword collides with it. I know onCollisionEnter is a way to do it, I also know raycasts are a different but more complicated way to do it.
I want for each sword swing to damage the enemy (Slimes for now, more enemies later.) incremently instead of an instant death. I have tried onCollisionEnter before, but couldn't get it to decrease in increments.
just, well... an instant death
the onCollisionEnter I have used is with the comparetag<> function.
it might also be important to know that I am on unity 2019.4.X
I have tried to use unity 2020.x but it was too taxing on my PC, as every time I would do something an application load thing would appear and it would be annoying.
Raycasts is not suitable for you if you are not throwing swords. You are using the correct way (collision), but you are missing a point:
This does not happen once when there is a collision. Lots of collisions happen consecutively.
To avoid this, you can close one of the colliders for a short time when there is a collision. (this means that: If the enemy has 100 health and we are decreasing 20 health with each hit, more than 5 collisions occur consecutively. Therefore, we are killing the enemy in one fell swoop.)
Or you can use a bool value (for example swordSwingCollisionActive). If the collision occurs after the sword is swung, you set this bool value to true. When the sword swing is over, you go false again. Just write if (swordSwingCollisionActive) return; at the beginning of OnCollisionEnter.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I want to make a chord playing box.
In a box (square) there will be one or more balls.
The square have normally 6 sides. On each side, I want to interactively divide it by 2by2 3by3 and so on..
For example, if i make one side by 2*2 plane, my 'tiles' will be total 24.
I call the divided rects, 'tile'. if the ball collides to a tile, then some music note plays off. Which means my tiles will be buttons to playing notes.
I used processing, and since I heard that Unity has good physics engine I tried doing my project with Unity. So I am new to Unity and C# but I do understand some programming languages.
My question is, How can I interactively divide planes in real time by putting in some input and make it as an instance, so that it can work as a independent button?
The easiest way is to use 6 planes (with colliders) for the six sides of your box.
Then you can use unity's Collider.OnCollisionEnter(Collision) method to detect the collision and get the ContactPoint where a ball touched the plane.
Unity documentation - OnCollisionEnter
This point can then be converted to the hit plane's local space using Transform.InverseTransformPoint. What you get is a kind of a normalized point (aka it is affected by the plane scale). Depending on the pivot of your plane you'll have to perform a translation for your x and y values to be between 0 and 1 (e.g. -0.5 on both axes, if you have a centered pivot).
Using these normalized coordinates you can "divide" your plane logically (e.g. a hit point between 0 and 0.5 on x and 0 and 0.5 on y wouldbe quadrant 0) . This saves you the pain of having to deal with multiple objects per box side which have to be seemlessly aligned etcpp.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 4 years ago.
Improve this question
I'm trying to build a 2D physics engine (rigid body dynamics simulation) in C#. So far I have simulated boxes (squares) of different sizes which are fixed in position but can rotate around their centroids (centre of mass) when a force is applied to them. This is the Box.ApplyForce() method that is called when a force is applied:
public void ApplyForce(double x, double y, Vector force)
{
//angular acceleration = torque(angular force) / moment of inertia
Force tempForce = new Force(x, y, force.X, force.Y);
forceList.Add(tempForce);
Vector displacement = new Vector(x, y);
double torque = displacement.X * tempForce.yForce - displacement.Y * tempForce.xForce;
double momentOfInertia = (mass*(size*size*2))/12;
angularAcceleration += torque / momentOfInertia;
}
Now this seems to be working correctly so far, but I now need to include translational acceleration in my simulation so my question is: what happens when you apply force to the edge (or any non-centre-of-mass point) of the object? Will the translational acceleration be the same as if it were applied to the centre of mass?
Are these simulated squares on a flat surface when simulating translational motion? Can they rotate when the force is applied, and also move translational?
If the box is on a flat surface it cannot rotate when you are simulating translation acceleration it does not matter where the force is applied. It just matters the angle at which the force is applied, or the component of the force vector in the direction of the translational motion. The component of the vector perpendicular to surface will affect the magnitude of the normal force, which will affect the frictional force if that is something you are taking into consideration.
If the box is not on a surface and just floating in space when the force is applied the answer gets a bit more complicated. Maybe clarify what you are simulating a bit more.
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 4 years ago.
Improve this question
I want to make the player move by a specific amount (1 tile/unit in this case) and then stop him. Just like in this video:
http://www.youtube.com/watch?v=DotOAbNngc4
By pressing a key the player should move smoothly to the next tile, than stops and so on.
How can I archieve this? (in C#)
You could take a look at GridMove which is from UnifyWiki.
You would probably get more of a response if you posted this question to answers.unity3d.com or forum.unity3d.com as these forums are specifically target towards Unity3d.
Here's what I would do: you give your player class a target field, e.g. a 2d vector. This will either contain the current position of the player (when initializing or when the target has been reached) or the target that you want to move the player to.
Now in your update you do this:
if target equals your current position then check user input for movement.
if user requests movement set target to position adjacent to current position.
else slowly move player towards target.
You may want to create a field for the current position of the player besides the normal position in GameObject. You could then update GameObject.position in the update-cylce by a small delta until the positions of GameObject.position and target have the (roughly! use epsilon when comparing) same value.
Some hints
Vector2.MoveTowards can help you
To check if the target and position are "close enough" you could subtract one from the other and look at the resulting vector's magnitude.
Beware of overshooting when you move towards the target. If your movement distance is more then or equal to the distance between position and target, just set the position to the target.