Why is this Framerate Independent When Adding An ImpulseForce Unreal Engine - unreal-engine4

I am facing an issue I want to push the object in the direction/Axis the player is moving towards I can do that using the getlastinputvector multiplying the force value but the thing is it is framerate dependent the output velocity is different when testing it in like 10FPS or 1000(uncapped)FPS how can i achieve the force not being affected by framerate and also the force being applied towards the player moving axis.

According to the documentation of add impulse: https://docs.unrealengine.com/4.27/en-US/BlueprintAPI/Pawn/Components/CharacterMovement/AddImpulse/
"If you want to continually apply forces each frame, use AddForce()"
The add impulse is good for something like kicking a ball where it only happens once and the framerate would not matter.
The add force is better for something like having your character push an object as it is designed to be used every frame.
In your case it seems you should use add force.

Related

I am developing a game at unity and encountered a problem while using accelerometer

I have written this code for adding a force on a 3d box using accelerometer but this has no effect on the box when running. Is there any way of using AddForce instead of transform?
Also I only want to add a force in the x-axis, means horizontally, and in no other direction. Is there any way to do this?
You might need to check your rigidbody mass with AddForce(). Force by default works with Newton's Law, that force = mass x acceleration. You might want to play with the ForceMode optional parameter that can be passed like: rb.AddForce(tilt, ForceMode.Acceleration). Acceleration adds a continuous acceleration to the rigidbody, ignoring its mass. More information on: https://docs.unity3d.com/ScriptReference/ForceMode.html
Or you might want to check rb.MoveToPosition(Vector3) that calculates force for you to move to specified position.
https://docs.unity3d.com/ScriptReference/Rigidbody.MovePosition.html
Information on the default way AddForce works, Rigidbody2D works in a similar way minus the third dimension.
https://docs.unity3d.com/ScriptReference/Rigidbody2D.AddForce.html
And to restrict force to only the x axis you might want to look on constrains on your box, limiting by axis or rotation.

How to get rid of acceleration during bouncing ? (unity 2D)

I don't know if this is the correct therm, but I want to get rid of any kind of forces that could modify the speed of my object. Let me explain : the game is 2D top-down view and the character fires a bullet that bounces x amount of time, WITH CONSTANT SPEED. Everything works fine, but when the bullet bounces fast and many times, its speed increases.
Also, second problem: I have a rotating object and when the bullet hits it, its speed increases (which makes sense, but I would like to know if there is a way to delete this effect) .
I would like to know if there is a way to solve my issues.
You need to check the material of the object for your first question (https://docs.unity3d.com/Manual/class-PhysicMaterial.html) you need to set Bounciness to 1 so it will maintain dame speed. If you set it to 0 there will be no bounce and probably you have a value bigger than 1 and so it's increasing.
In the second case it's all about the forces involving. The object bouncing on the rotating one is adding a force to that one. If you want to keep the second one with same rotation you could rotate it with a transform.Rotate and remove a Rigidbody or set it to static

Unreal Engine 4 - Add offset to character movement

I just started (yesterday) using unreal engine and I need to simulate a drunk character using BPs.
I'm using two camera shakes (one for standing still and one for walking) but I want to add some "displacement" on charater when he's walking.
Basically I want to define a random float to be added to X axis location in order to make character wobble smoothly.
It will be acceptable even if there's a way to make the character move along with the camera when it's shaking.
What I tried until now is using AddActorLocalOffset and a timeline to lerp between actor's location and actor's location+offset, but both are very choppy to me.
Maybe it's a noob question but as I told I'm very new to this and need it for a quick work.
Any suggestion?
Thanks
If you are targetting physically correct model, you should use AddForce (UE Docs). But this approach would require implementation of a "drunk animation" where your character will modify it's movement animation to "compensate" this force by stepping aside etc.
Another (much more simple) approach is by using AddMovementInput. This example can be seen here: UE Aswers. In this case, you are basically simulate player's input by adding small amount of side force here and there.

How to move character with permanent speed in Unity2D

I'm creating Unity2D runner where characters is running on the ground.
I'm trying to force him run with constant speed by applying force with right vector but the movement is jerky.
I'm trying to achieve effect of endless run with permanent speed. It is easy in the air but works different (because of physics) when character is running on the ground.
You could velocity and make sure to turn off gravity. If you are running on the ground make sure you turn this off.
You could implement your own movement where you can update position depending on Time.deltaTime.
Just use the built in character controller that unity comes with. basic directionals and jump. And mouse controls where the character faces.
EDIT:
Use rigidbody velocity and turn off gravity and drag. This will keep your runner running forever.
To implement this yourself. You can update the position of the object in the update method. Something like
Vector3 temp = object.transform.position;
temp.x = speed * Time.deltaTime;
object.transform.position = temp;
Where object is you runner and speed is how fast you would like him to move.
This would be inside the update function.
If you aren't going to be controlling the runner, dont bother with the controller
Use Rigidbody2D.velocity and pay attention to:
The velocity can also gradually decay due to the effect of drag if
this is enabled.

Making a unicycle with Box2D

I'm fairly new to Box2D and trying to figure out the best way to make a unicycle. The unicycle essentially is in two pieces, the wheel and the stem (with seat post etc). I've tried attaching the two with a revolute joint and using a motor for the wheel, which works well except that the stem is then subject to forces from the movement of the wheel. I want to be able to directly control the rotation of the stem (via the accelerometer on the iPhone), and have it unaffected by the movement of the wheel, except to maintain its position based on the position of the wheel.
What is the best way to do this? How do you control rotation of b2Body's? Should I be using a distance joint instead? Any help would be appreciated.
I see several routes, depending on your needs. Which way is preferable is up to you and your game.
1. Fix the stem's rotation
For the bodyDef for the stem set the fixedRotation-flag to true. This prevents any rotation of the stem (be it by forces from the motor joint, (de)acceleration or collisions.
Than you'd have to manually set the rotation each tick. This is easy if it's purely based on the iPhone's position. If you still want to calculate other factors into it, things might get from a bit more complicated (e.g. adding rotation if stem leans too far in one direction) to somewhat painful (have collisions affect the rotation).
2. Constantly apply balancing forces to the stem
Each tick read the stems angular velocity and apply countering forces to balance the stem.
While this would probably be more complicated to implement correctly (always find the right force to apply etc.) it may result in a more realistic behaviour as the fixed rotation obviously removes most reactions stem movement would have and how the stem itself is affected by the world.
3. Don't actually use a wheel
While your layout is the obvious choice for a unicycle (and seems to be a somewhat popular choice for all kind of characters) it might not be the best choice from a gameplay point of view.
Instead you could combine the stem and wheel fixtures in a single body (or attach them with a prismatic joint) and create all movement by applying forces to this body. A sensor at the bottom can inform you of ground contact to determine if movement forces are to be applied.
This way you'd get rid of all the forces a wheel creates (forces to the stem may not be the only unwelcome ones in gameplay) and still have it react to all external forces.