How do you reduce the drag experienced when jumping in unity? - c#

I've created a player character in Unity and jumping works like it should.
But when she starts to fall back down to the ground, I want her to fall quickly.
She is almost floating back down, which interrupts the level's feel.
What parameter am I missing that allows her to fall back to the ground?
I'm going for a Mario feel, where he crests at the jump and then falls fairly quickly back down to the ground.

Simply add more gravity to whatever component that controls your characters' physics e.g. If you are using a rigidbody component then increase the gravity property.

Related

How to move enemy characters?

I have random enemy characters spawned into a map using Unity 3D. The enemies have rigid bodies with gravity enabled. I use MovePosition to move them around the map (in the 'forward' direction) in the Update() method and select a random rotation so they 'wander' around randomly.
Because gravity is enabled when they walk up or down hills on the island, it all works correctly (they stick to the terrain).
The problem arises when I fire an arrow at them. Sometimes they start floating upwards into the sky, despite gravity being turned on.
I tried using AddForce() instead, after reading that may be more appropriate for non-kinematic rigidbodies, but movement became very erratic and so went back to movePosition.
Any ideas how I can stop them floating upwards when hit by arrows sometimes? I'm guessing having enemies walk around randomly and then be able to be hit by arrows must be a fairly common requirement for game designers, but not been able to find a best practice method to use anywhere on google?
void Update() {
...
rigidBody.MovePosition(rigidBody.position + movementDirection * 0.4f * Time.deltaTime);
...
}
It turned out it was due to internal inertia on the enemy objects - just found this video during lunch. Another unityism... so frustrating, but hopefully this answer helps out others in the future:
https://www.youtube.com/watch?v=maIAiSRBEdE
It turned out Fixed constraints were being ignored by unity because of the internal inertia being set on the objects rigid body.

Unity OnTriggerEnter is not being called

I have a flying Dagger with a trigger surrounding it so when it hits an enemy or wall it returns. However sometimes the Dagger just flies straight through. I suspect that happens because its velocity is too high(200), is there a way to fix that?
This is, almost for sure, caused by the high velocity, and in fact this problem is known as "bullet through paper". There are some tricks to address this issue.
As a start, if you are using a Rigidbody, you can go for the dynamic collision detection: this reduces the performances, but it helps a lot for this problem.
You can use Raycasting rather than Collisions, in order to check for the bullet impact.
A trivial advice: in case of the walls, you could just extend the collider in the direction for which the scene does not take place anymore: this way, you would have "wider" walls, but outside of the game field.

Unity Rigidbody has velocity but not moving

I have a game in Unity where cubes are repeatedly moved past the camera. I move the cube using a script where I set its Rigidbody's velocity each update. Once it moves out of view my script instantiates a new cube on the other side which begins the process again.
Recently I've found that it works fine for a random amount of cubes before, seemingly randomly, a cube is instantiated that does not move. Using the inspector I can see that this object has velocity. If I move it even a small amount using the editor it starts to move as normal.
Has anyone seen something like this before?
I'm fairly certain the problem was related to the fact I was trying to directly modify the velocity( The physics engine decided the object was at rest and stopped it moving. ). By setting the object to be kinematic and modifying its position in my code I solved the problem.
May be you are changing the velocity of your gameObject when it goes through a specific coordinate (in an if statement for example), unity is not very accurate sometimes with coordinates so it may be happening that the condition is never met. Change that condition and add a margin range to solve this error.

How to handle multiple rocket thrusters?

I'm fairly new to game development and I'm trying to develop a 2D game in unity where the main character has a jetpack with two thrusters and I want him to control each one individually. So if he only turns on one thruster he goes 5 meters above ground and hovers there while using both would make him hover at a height of 10 meters. How would i go about doing this?
I tried just simply adding forces as if the character was jumping and freezing the y-axis to 0 until he let go of the jetpack button but that did not give me the feel i was looking for. I also tried raycasting a line out of the jetpacks to the closest surface and adding a force to the jetpack to allow the player to float at that height but that I couldn't figure out a proper way to implement it.
The Raycast sounds like a great idea. Do the raycast to the next available platform and do as #Ahndwoo said in a comment, `
What you would need to do is divide the force of your thrusters by the
magnitude of the Ray. Thus, as the Ray gets longer, the force
decreases.
By doing this you'll get the natural movement from a force and you'll control how high can you get.
I would Make your thrusters holder as an object and as more turbines it has, the more powerful i'll get.

Character slowly move up the ground using a humanoid animation type in Unity

I have a marine model used in my start project, which will uncontrollably lift off the ground when running. I import the fbx resources, set the animation type as humanoid and configured the avatar by automatically mapping, set up a animator controller that contains only a running animation. Here is about several seconds after playing:
But when using a generic animation type everything works fine. Any suggestions to fix this while still using the avatar system?
UPDATE:
Configure of my 3D model:
This is obviously caused by root motion. What happens is, one loop of your animation takes the character slightly higher. Adding these slight changes up, you get what you're getting. If you don't need root motion (doesn't look like you do), disable it (from the animator component's settings). If you do, either edit the animation to make sure it fits, or disable root motion along the Y-axis (you can do this from the animation's import settings).
In case you don't know what root motion is, it's when the root bone of your model has animations applied. You obviously can't create the entire animation of character running up and down your levels, and until recently (though not MUCH recently) characters where animated in-place, and moved procedurally via code (I know for a fact that Unreal Tournament 3 uses this method, as would any UDK user). Then, people started wondering how they could make their characters move more realistically? I mean, it's not like you walk forward at a constant rate of 4 km/h, you tend to slow down and speed up during different parts of the walk cycle. The same can be applied to video game characters using the technique known as root motion.
With root motion, you actually move the character forward during its animations. This will cause an animation to look really bad in max or maya, since the character will just snap back to its original place after a loop. However, this data is used intelligently in game engines: Rather than use the absolute position the animation yields, you take the velocity out of it between each two frames, and move your character based on that velocity (Unreal engine actually has a really neat acceleration mode for applying root motion, though I'm not really sure how that would be different from velocity mode). This will make your character move forward at the same rate the animation does, and thus you can actually animate the character's movement as well as its limbs and joints. Moreover, since you're using the velocity and not position data from the animation, it will look exactly as you'd expect it to. If you're interested in this technique, take a look at the Mechanim demo pack they have on the asset store. It makes extensive use of root motion to move the character around.
My company was having a similar issue but we still wanted to keep the "Apply Root Motion" toggle checked. When the same animation played on loop, the model stayed in place but if several different animations were played one after another, this caused the model to rotate / shift in position.
The solution for us was ticking these check boxes in the animation settings for each animation. Root Transform Rotation, Root Transform Position (Y), Root Transform Position (XZ).
I had the same issue a few days ago. I found out that the problem was the Apply Root Motion in the Animator script. Make sure it's unchecked.
Tag your player with "Player" in scene
and use this script
float y;
GameObject player;
void Start ()
{
player = GameObject.FindGameObjectWithTag("Player");
y = player.transform.position.y;
}
// Update is called once per frame
void Update ()
{
float diff = player.transform.position.y;
player.transform.Translate ( 0, 0,z - diff);
y = player.transform.position.y;
}
it is little hacky soultion but works!!
note: if you want to use y movement at some point just calculate and add it to diff variable.
For those who couldn't solve this issue with 'bake into pose'.
I tried 'Bake into Pose-Y', but it didn't work.
Meanwhile, in FBX > Animation > Motion, I set 'Root Motion Node' as 'Root Transform'(It was 'None' before), it solved my problem. Unity version is 2020.3.34f1.

Categories

Resources