AddActorWorldLocation method unintentionally changes the roll value of my object - unreal-engine4

I'm trying to rotate an object by dragging it through linetrace. Everything work good except that my object starts to rotate as if I were passing It the roll value too.
Is there a way to continuously set the roll value to zero to avoid this unwanted rotation?
Thank you very much.
Here is the blueprint.

Set the actor's rotation with SetActorRotation with Roll 0 and apply GetActorRotation's Pitch and Yaw to it after AddWorldRotation. That's if you want to continue using AddWorldRotation.
I personally would use GetActorRotation + DragWorldRotation then SetActorRotation with Roll 0. This is without using AddWorldRotation.

Related

Why is this Framerate Independent When Adding An ImpulseForce Unreal Engine

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.

Stuck Implementing A Way To Rotate A Rigidbody Towards A Point With Rigidbody.AddTorque

So I am kinda stuck on what to do now because as I said I am trying to use Rigidbody.AddTorque to rotate a rigid body towards a certain point, which I was going to use to align a player with a gravitational pull so they can be upright. I have got the input part of the code, I just don't have a way to rotate the player to align with it, without violating the laws of physics with Quaternion.FromToRotation and messing with my character controller too, which I am trying to make entirely physics based rotation wise too to avoid any other problems.
I have experimented with a couple of methods, first I tried adapting my character controller code which used Rigidbody.AddForce to move the player and also dampening unwanted movements, as Rigidbody.AddTorque is basically Rigidbody.AddForce but for rotations, however, it was too weak and just flopping around when I tried it, here's the code for the character controller for calculating the force needed for one axes:
if(projected_speed.x*speed == relative_v.x)
{
applied_speed.x = 0f;
}
else if(Mathf.Sign(projected_speed.x)== -1)
{
applied_speed.x = relative_v.x - Mathf.Abs(projected_speed.x*speed);
}
else if (Mathf.Sign(projected_speed.x) == 1)
{
applied_speed.x = projected_speed.x*speed - relative_v.x;
}
Where projected_speed is the speed the controller wants to be at,relative_v is the relative velocity, and applied_speed is the speed that will be actually applied in Rigidbody.AddForce.
Anyways so maybe I didn't use enough force, as the player is under a gravitational pull, but that would have probably made it flip out or something, anyways so the second thing I tried was a PID controller, and I managed to find a page which explains it pretty well, sadly don't have the link anymore, but when I tried this because you have to tune it, I was stuck doing it, and it just wasn't able to do anything and was just rolling around the floor and sometimes spinning, probably as it couldn't cope with gravity, so that didn't work, so does anyone know how I could finally do this and make my character able to right themselves according to gravity?
Sorry for not indicating that my issue is solved, click here for the answer, credit to Ruzihm.

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

Have fixed speed with AddForce?

I want to use AddForce to move an object with a fixed speed but when I use AddForce the speed of the rigid body increases in crescendo.
AddForce adds a force to me every time I hold the input down, the more I hold the key to move the object the more force is added, while I always want to move the object with the same force.
You may set the velocity directly instead of adding accelerated force every frame you hold down the button. So instead of using AddForce(), you can access your rigidbody's velocity like in this example.

How do I make an animation not reset the position of the object?

I was trying to make an animation in which the object at hand moves to the right a certain amount. However I discovered that if I animate the object at -3 and make it move to -1.5, whenever the animation is executed, the object flies back to -3 and goes to -1.5, instead of moving 1.5 units to the right (that's probably how it's supposed to work). How do I make an object move 1.5 units to the right using the Unity animation system, regardless of current position?
The simplest way to make animation do "relative" motions is to attach your object to a parent object. This way the object animates relative to its parent's transform.