How do I force orbital movement around a point in space, while maintaining forward/backwards capability on a player? - unreal-engine4

Long-winded question out of the way, I'll provide a diagram of what I am going for:
The red square represents the character, the blue rectangle represents the camera, the green dot represents the center of the "stage", and the black circle is the stage itself.
What I desire is to essentially lock the player's movement around the "center" of the stage, so that anytime you move left or right you are more or less rotating around said center. However, I also want the player to be able to move forwards and backwards to/from the center as well. Keep in mind I want the camera to always stay directly behind the player. I have tried many different methods, and the latest is the following:
I took a default actor, attached a spring arm, attached a child actor to that (gets possessed to become the playable character), attached another spring arm, and finally the camera to that. I then added the blueprint code to the first spring arm so that it was the one being controlled by the left/right controls. However, upon hitting play, the only thing that moves is the camera, and it can only move forwards and backwards.
I'm admittedly pretty new to Unreal Blueprints, so any help would be appreciated.

Alright, I figured it out.
Here's the setup needed if anyone else wants something similar.
For the player themselves, you'll need something like this:
The important thing is to center the root mesh where you want to rotate around. The spring arm's target arm length will be affected for the player mesh movement, giving the illusion you are physically moving the character. The second spring arm isn't necessary unless you wish to have more control over the camera to player distance.
For the rotation Blueprint, you'll need this:
The target is whatever you named the root mesh. (Mine was called Center) Drag and drop it from the hierarchy.
For the forward/backward movement, you'll need this:
The target is what you named the spring arm. (I left mine as the default "SpringArm") Again, just drag and drop it from the hierarchy.
Adjustments in Project Settings:
Yes, my inputs are backwards from what you'd think. I felt it was quicker just to reverse the inputs instead of adjusting whatever was causing the movement to be backwards in the first place. (It's probably just the sphere orientation.) Also, you'll notice I have the w and s inputs set to 5 or -5 instead of 1 or -1. This is due to the fact the movement was slow otherwise. I'm sure there's a fix that doesn't involve changing the input axis scale, but honestly I won't really have a reason to alter the values at any point in my project. If it ever comes up where I do need to, I'm sure there's a bypass to change the values from within blueprints anyways.
End result:
End Result Video

If I remember correctly, child actor components are a bit different from other components in that they are transformation independent, that is they do not update their transformation when their parent component moves around.
I find it a bit strange that you would separate your player actor and the camera component. Normally, the player "pawn" contains the mesh and camera components for one player.
I would suggest you do the following:
Create a player actor (e.g. a "pawn" or "character" class)
Create the following component hierarchy:
Root Scene -> Spring arm -> Skeletal or static mesh -> spring arm -> camera
Your root scene is the green center in your drawing. You can then basically use the blueprint you already have to rotate and move your player.

Related

How to make a terrain that acts like the globe?

I want to make a terrain where the ending point is also the starting point. So, like on the earth you could just go on walking straight and you would reach the point where you started again after some time.
Thanks for your help!
Unity's Terrain system can only create square regions of terrain. So this can't be done as such.
However, you can approximate it, and I'll tell you how I've done it in my project to some success.
Figure out how much terrain you need to cover the "globe", we'll say it takes NxN chunks of terrain we'll call a "tile".
What you do next is you make 9 of those NxN tiles, and arrange them in a 3x3 grid. Put the camera in the center tile of the grid, and whenever the camera leaves that tile, determine where it is on the tile it is on, then change its position to the corresponding position on the center tile.
This will give you a "toroidal" world. I found this was the easiest solution to get the player to see things on the other "corner" of the world map, and then cross into it without graphical issues.
If you have other objects residing on the world, that presents some additional challenges. One thing you can start with is duplicating them 9x and start them at the same relative position of each tile. If they only interact with the player, that should be fine, just whenever the player interacts with 1, the other 8 do whatever that 1 does.
If the other residents of the globe have to interact with each other, you'll need a way to figure out how to make all 9 copies of everything behave consistently, but that's too broad of a question to address here.

How do you wrap a level around based on the players position

I want to create a circular room in a 2D level. How can I handle this problem?
My thought process was to break the level into chunks and move their position depending on where the player currently is. This would allow the level to wrap around depending on where the player travels. I can do this manually with each part but i'm looking for a better solution that can handle this programatically. I'm open to better ways to solve this problem as well.
Is the space 2D? if so, you could place two invisible colliders at the extremities of the room (one at the beginning and one at the end), and change the player's position when he collides with them. To ensure that the transition is smooth, place them a little outside of the camera space: the player won't be rendered during transition, and you would obtain a teleport effect from side to side.
As another suggestion, you can lock the player to being in the center chunk with a camera just showing that chunk. Everytime he gets through a collider on the end or the start of the middle platform you delete the opposite side platform and place it in the far end of the platform the player is now seeing, effectively making the new platform as the middle one.

Character Pawn sliding back when picking up objects

I am using Unreal Engine to create a puzzle game. In this game, the player has to pick up a chair/table and place it on a pressure plate in another part of the room in order to unlock a door.
When play testing, picking up objects causes my character to slide back. Once the sliding starts, there is no way to make the character stop sliding. I suspect that this issue may be caused by the object's collision volume entering the character's. However, when I release the object, my character keeps gliding backwards even though by then, the object's collision volume is out of reach.
On my character's blueprint I have locked rotation on all axes, so that it won't randomly start rolling backwards after picking up an object. This solves part of the issue but there is still the gliding that just won't stop.
I am new to UE and I have no idea what may be causing this issue. If you have any previous experience in this or simply want to chime in, please do!
Another alternative fix is to lock the rotation of the collision component in the default pawn that you have or to increase angular damping.
To do so, open the default pawn blueprint and under the physics section, then constraints, lock rotation in the X, Y, and Z axis. Or increase angular damping.
Dont know why this is happening exactly unless we see the actual settings you are using and the BP but when you pick up the object , disable its physics and collision and when you put it back enable it after a delay of 0.5 or 1 second . Hope this helps.

In Unity, how to prevent animations from messing with the movement?

The problem:
I have a character model with a Nav Mesh Agent component. It moves perfectly well to any destination I tell it to move (using the NavMeshAgent.destination property).
But this suddenly fails as soon as I use an animation controller I downloaded from the store. The character won't run to it's destination; instead, it will endlessly run around it in circles.
I'm not sure why this happens, but I suppose the running animation somehow cripples the character's ability to turn. The Inspector, in the import setting of the relevant .fbx file shows: Average Angular Y Speed: 0.0 deg/s.
What I really, really fail to understand is why this keeps happening even though I have explicitely set NavMeshAgent.updatePosition and NavMeshAgent.updateRotation properties to true. The way I understand the documentation, this should make the character move as the Nav Mesh Agent wants it to move, and not as anything else (animations included) wants it to move?
How should I fix this problem? How should I force the animation not to meddle in the movement?
Do all your animation in place and use code to do the movement and you can uncheck root motion and use state machine values to get a better movement or use root motion and let mecanim`s retarget engine do the blending so go see for yourself what gets you better result , so I guess your problem is that your animation are not in place.
First: one of the biggest plus of Unity is its mecanim. Disabling root motion is negating a big advantage.
Second: the reason your character is running around probably is because the animator and the navmesh agent are issuing conflicting orders. Use updatePosition to false and updateRotation to true. Hence, the animator controls how fast you move and the navmesh agent controls the angular speed. Other posible cause is that your destination is unreachable. Check the Y component of the vectors and insure they are coplanar.

Dragging a Sprite (Cocos2D) while Chipmunk is simulating

I have a simple project built with Cocos2D and Chipmunk. So far it's just a Ball (body, shape & sprite) bouncing on the Ground (a static line segment at the bottom of the screen).
I implemented the ccTouchesBegan/Moved/Ended methods to drag the ball around.
I've tried both:
cpBodySlew(ballBody, touchPoint, 1.0/60.0f);
and
ballBody->p = cgPointMake(touchPoint.x,touchPoint.y);
and while the Ball does follow my dragging, it's still being affected by gravity and it tries to go down (which causes velocity problems and others).
Does anyone know of the preferred way to Drag an active Body while the physics simulation is going on?
Do I need somehow to stop the simulation and turn it back on afterwards?
Thanks!
Temporarily remove the body from the space.
If you want the object to have inertia when you release it, that's a different story. The cleanest way is to attach a fairly stiff spring between the ball and a temporary sensor body that moves under the control of your finger. When you let go with your finger, the ball will retain whatever kinematics it had while you were dragging it. Be sure not to remove the ball from the space in this case.
You aren't updating the velocity of the object when you aren't using cpBodySlew(). That is why it falls straight down.
A better way to do it is to use a force clamped pivot joint like the official demos do to implement mouse control. http://code.google.com/p/chipmunk-physics/source/browse/trunk/Demo/ChipmunkDemo.c#296