Unreal Engine: Constrain a pawn's rotation between two angles - unreal-engine4

I'm working on a short Unreal Engine 4.9 blueprint for a friend, but I am not familiar with the unreal engine at all, and I'm about to pull my hair out. I've been searching online for about 2 hours, and I can't get it.
What I'm trying to do is get the roll of a object, derived from the pawn class, and lock it in between two angles. In pseudocode, do this:
if MyObect.Roll < -50,
MyObject.Roll = -50;
if MyObect.Roll > 50,
MyObject.Roll = 50;
Any sort of help or pointing in the right direction would be a huge help. I've seen some post using a player camera manager, and no luck from that thus far. Thanks in advance.

First thing to do in such a situation is print your values, e.g. using UE_LOG. You'll notice that your values are often between 0 and 360 instead of what you might expect yourself (-180 to 180).
So, you'll need to 'normalize' your angles first, to get them to be between -180 and 180. That way you can use the code you posted above :)
if (MyObject.Roll < -180.0f) MyObject.Roll += 360.0f;
else if (MyObject.Roll > 180.0f) MyObject.Roll -= 360.0f;
Hope that helps!

Related

How is force applied to multiple objects?

I am trying to make a waterful ring toss game, but I have difficulty applying power from one point to all objects in the game.
Basically, what I want to do is to add force to all objects located between x and y points to move by applying force according to their positions.
I've been doing research on Unity forums, Stackoverflow, and Unity documents for a while, but I haven't been able to find what should ı do or use.
I'm looking for resources or suggestions to help me solve this problem. I apologize in advance if I asked the wrong question. This is my first question on this platform.
Here is an example screen:
The solution I found thanks to the comments:
if (buttonPushed == true)
{
for (int i = 0; i < ringObject.Count; i++)
{
ringObject[i].GetComponent<Rigidbody>().AddForceAtPosition(Vector3.up * force, transform.position);
buttonPushed = false;
}
}
Simple way
You put your objects in a list and iterate over them and do whatever you want to do in a if statement in that loop.
Harder way.
Create an object in that area with a collider and get callbacks when your object collide with that big collider object.

Are eulerAngles reliably to use for local rotation limits?

I want to allow the camera a certain local rotation (orbit around the player).
To do that, I calculate a rotation first, then I look at the EulerAngles, and then I state something like this:
if ((rotation.eulerAngles.y < 250) && (rotation.eulerAngles.y > 30))
{
//apply rotation
}
I would like to ask if using eulerAngles this way / for this purpose is safe or if there is a better method to limit a local rotation?
I'm asking because somebody said that "eulerAngles are ONE expression of a many possible eulerAngles expressions for a certain rotation." (I hope I got that right). That made me wonder if they are reliable.
Thank you!

I can't get the right rotation of my transform in unity 3D

Hi everyone I have some little problem in Unity 3D. I am trying to do some walking simulation I have character and I have joints while she was walking I want to get the rotation of y. But when I try it I get some results like (transform of rotation in unity is -60 for example the value I get in program 0.059871 something like that how can I read the -60 the right value?)
Maybe you take the wrong properties, the Quaternion.y is a value from 0 to 1 (CMIIW)
but if you want to get you rotation in degree you can use Vector3.y by taking
var y = gameObject.transform.localEulerAngles.y;
Also, please attach your code before asking some code related issue

Get the position behind an object (locally) ? - Unity3D

I ran into a problem while making my complex(ish) camera behaviour (using Javascript). The problem that i have run to is that i am not able to get the position behind my player. Please don't tell me to use Vector3.back etc.. , because i want the position locally, to support turning. It won't work if the camera is always set to that position, cos i have a cool movement system in place.
I tried a number of approaches, and confused myself with the math. I also tried complex addition and subtraction. None of them worked at all.
I guess i am probably missing something quite simple, like a way to get into local coordinates etc.. ( or maybe a few math functions )
thanks in advance
-Etaash
You can get the forward vector of any transform, and if you negate that it is the backward vector. So on a script attached to the player you would have:
Vector3 backward = -transform.forward;
So to get a position, you could do something like this:
Vector3 pos = transform.position + (backward * dist); // where dist is a float to scale how far away from the position you want it

Help Required in Collision Detection Using Box2d

After some sample projects, I have started with my first game in cocos 2d and box 2d where objects fall from a parachute and you kill them using slingshot. Now i'm stuck # couple of things for a while:
Collision Issue:
Using Box 2d i have made collision with objects. However when i add a counter to get a count of my collision i doesn't work. Counter increases even though the percentile is moved out of the screen.Don't know how to get rid of this.
I'm trying to get random rotation to my sprites which fall from above, Like a parachute experience. Now all of then rotate # a same angle.
Lastly i need to get rid of the surrounding sprites when collision happens. Ex: When the percentile collides with a falling object, in a radius of 2.5 cms the other sprites should also disappear.
I Badly need help and suggestions, hence all the 3 questions # once :-). I have provided the link for my project so that you can look # the source code. Desperately looking for your help guys!!!
Download Source Code:
http://jumbofiles.com/6fn5mmpnq1q8/Karthik.zip.html
Budding Developer,
Karthik
You have a pretty good tutorial here: http://www.raywenderlich.com/475/how-to-create-a-simple-breakout-game-with-box2d-and-cocos2d-tutorial-part-12
I think that one can solve your problems :)
You can get the best tutorial for the particular requirement you have described over here.....
The link for that is as follows
http://www.raywenderlich.com/606/how-to-use-box2d-for-just-collision-detection-with-cocos2d-iphone
The tutorial is of 2 parts and describes the code briefly.. The code of that is described and you can get good amount of help from there.
ques 1 + 3: you need read link which share by Mikael and Marine
ques 2: in cocos2d, if you want get random value, you can use support function (such as: rand(), random(), CCRANDOM_0_1() ....)... i think, you need set rotation value for object. i dont know your problem, you need explain it (link is "File Not Found or Deleted / Disabled due to inactivity or DMCA")