Unreal Engine Ray Cast is not in player y (pitch) rotation - unreal-engine4

Start and End position of the ray cast
I need a way to make the end position of the ray cast rotate like the players y (pitch) rotation.

Related

Object Rotation in unity3D

I am currently working on a game
I have two in-the-game objects which are the stone and arrow that attach to the vehicle
arrow has attributes of x, y, z,
rotation, rotation y, rotation z
Changing rotation x will make the arrow turn left and right, the rotation y is the up and down and z is like the wing
What I want is to point the arrow into the position of the stone
I appreciate any help
To make arrow that attach to vehicle point to the stone
I think transform LookAt is what you're after.
arrow.tranform.LookAt(stone.transform);
https://docs.unity3d.com/ScriptReference/Transform.LookAt.html

Unity3D: Contrain movement to one axis at a time

I am making an isometric game in Unity. Im using a 3d cube as an agent for my 2d sprite. I have set up animations so that the sprite turn in the direction it is walking, however the cube is not walking in one axis at a time. Instead the cube moves in both the x and z axis, this messes up my animations. How am i suppose to contrain the cube to only walk one axis at a time so that the animations turn out correctly.
If your cube has a Rigidbody attached, you can check the axis you want to freeze under Rigidbody > Constraints > Freeze Rotation.

Calculating 2D parabolic trajectory for a projectile to hit a position

I'm developing a Tower defense in 2D in Unity.
I'm trying to calculate a parabola to draw the trajectory of the projectiles fired from a tower in the game. I've got the position of the tower and the position of the enemy - now I need an algorithm that calculates a parabola that will hit the enemy.
Is there a universal algorithm or something like that for this kind of calculation?
Assuming gravity but no drag we have:
where
x, y is displacement
x_0, y_0 is initial location
u_x, u_y is initial velocity
g is acceleration due to gravity
t is time elapsed

Unity3D relative rotation of objects on an axis

In the project I am using IMU sensors to track real player's hand and apply the transformation values onto 3D hand inside Unity.
As IMU sets the Y axis orientation relative to magnetic north of the earth, in the game, hand initializes on specific direction.
What I want is to calculate the offset of IMU's given Y values and 3D hand's original Y rotation, so that I can subtract that value to the 3D model's Y rotation (that will seem like player's initial Y Rotation is the same as 3D hand's). Code would be: transform.Rotate(Vector3.up, offset, Space.World);
IMU sends Euler angles (does it well, as I wasn't able to get Gimbal lock)
As I understand, I need to find out angle difference between 3D Hand's initial rotation and IMU's given initial rotation on XZ plane (or through Y Axis)
How do I calculate the offset?
You can use Quaternion.FromToRotation to calculate offset, something like:
var offset = Quaternion.FromToRotation(Vector3.up, imuUp);
transform.rotation *= offset;

Issue with throwing b2body at particular angle in Box2D game

in my game im having one Ccsprite for arrow, and one b2body for ball... im trying to throw ball at direction which is pointed by my arrow sprite. here is my code... i'm counting rotation of arrow sprite and then applying impulse to ball at that angle...
float totalRotation = arrow.rotation ;
ballBody->ApplyLinearImpulse(b2Vec2(10.0f+cos(totalRotation)*25.0f,10.0f+sin(totalRotation)*25.0f), eggBody->GetWorldCenter());
BUt, this not working exactly...ball is getting thrown in improper direction.
The rotation property of a CCNode (and CCSprite, which inherits from CCNode) is measured in degrees, with clockwise rotation being positive. The Box2D world uses angles measured in radians, with counter-clockwise rotation being positive, which is more conventional for a cartesian coordinate system. In order to provide the correct angle to a Box2D function, you will have to convert. In Cocos2D, the conversion goes like this:
float angle = - 1 * CC_DEGREES_TO_RADIANS(totalRotation);
The macro converts the totalRotation from degrees to radians, and you multiply by -1 because Box2D measures positive angles in the counter-clockwise direction, which is opposite of the CCNode rotation.