I have this third person character blueprint in which I'm trying to hide the character mesh if the CameraVisibilitySphere component overlaps the character. It actually works, but only if the character moves.
If simply I move the character close to an object, rotate the camera so that it collides with the object and gets closer to the character, the mesh won't disappear. But if I just move the character a bit, no matter in what direction and so that the sphere still overlaps with the character, Is Overlapping Component returns true as it should and the mesh is gone.
When the mesh is not visible, without moving the character, and I rotate the camera so that the visibility sphere doesn't overlap anymore, nothing happens. If then I move the character, the mesh reappears.
I tried using OnComponentBegin/EndOverlap and I've also coded it, but nothing changes, it shows the same behaviour.
The code I set the sphere with is this:
CameraVisibilitySphere = CreateDefaultSubobject<USphereComponent>(TEXT("CameraVisibilitySphere"));
CameraVisibilitySphere->SetupAttachment(FollowCamera);
CameraVisibilitySphere->SetSphereRadius(12.0f);
CameraVisibilitySphere->SetCollisionProfileName(TEXT("Actor"));
CameraVisibilitySphere->bGenerateOverlapEvents = true;
CameraVisibilitySphere->OnComponentBeginOverlap.AddDynamic(this, &ABatteryCollectorCharacter::OnCharacterBeginOverlap);
CameraVisibilitySphere->OnComponentEndOverlap.AddDynamic(this, &ABatteryCollectorCharacter::OnCharacterEndOverlap);
BTW the character's capsule is set to generate overlap events and to overlap with the camera.
What should I do to make this work? And, most importantly, do overlap events get called on child components of the same actor?
I'm new to Unreal, so I still don't know the environment very well.
Overlaps created in the parent are inherited in the child. You might try getting your Camera and do a MultiLineTraceByChannel, break the hit result and cast the hit actor to your character, then in your character, fire off the code to hide the actor with a custom event.
Related
How to adjust the speed of the character when crossing a cube with water?
And how to make it move more slowly on the surface of the water, while leaving the ability to move with Shift?
Speed up movement when pressing Shift
Water surface blueprint
Water surface blueprint components
Put an OnComponentBeginOverlap event on 'BP_WaterRegion' that checks what kind of actor it's just overlapped with. If it's the player character then you can set the MaxWalkSpeed variable on the character from there. The OnComponentEndOverlap event should be self-explanatory now.
If you select 'WaterMesh' you should find these events at the bottom of the Details panel.
(It's a while since I've worked in UE - you might need to connect the output from the cast node to the == node instead.)
Have Mesh Colliders on everything except the Solider being a child of the Game Object renamed Player.
The Player has a Character Contoller surrounding the child or blue-colored soldier. In Game Play, he falls halfway through the road and gets stuck in Unity. Is there a fix for this????
I noticed the Unity forum had not answered a similar question about it since 2019.
Colliders
Make sure that the actual model / mesh of your character has a mesh collider applied to it and that the convex box is checked. Next make sure that your ground / whatever your character lands on has a collider attached to it whether this collider is of type mesh, box or really any collider it shouldn't matter but I'd recommend trying a cube with a box collider first. Also make sure that all of your mesh colliders actually have a mesh applied to them.
For your character controller double check that the size of it matches your characters model in both width and height. Apply the actual Character Controller to the Parent game object in your case named Player and apply the mesh collider to your actual character.
Some Images of how it should look when correctly set up
How the parent "Player" should be set up simply
How the actual character should be set up simply
How your ground should be set up simply
So, lets say my character has the ability to push "movable" objects. This is alredy implemented and working as desired.
But I want to make the characher be pushed back if he tries to push an object that is hitting a wall or an immovable object, is there a way to see if my add impulse had any effect?
Or a best way to do is some ray casts on the movable object boundaries to see if is touching any other thing?
For characters you can use Launch Character. It's like adding velocity giving a specific direction. Add Impulse is intended to be used with Objects that simulate physics.
Just Launch the Character to a direction opposite the direction it's touching. You can use Dot Product between Character Velocity and the Object Face (forward).
I have a character which is controlled with physics stuff like Spring Joint and Constant Force (The character is active ragdoll).
I want to stick the character's legs to the ground and when it is bent left and right, the entire character doesn't move on the ground.
What is the way to achieve it ?
Currently I use Fixed Joint on both legs with Constant Force but still the character moves around when there is sudden force on upperbody.
As you can see in the gif.
I'm using the first person controller for my characters movement. On a left arrow keypress, I'd like the character to instantly rotate 90 degrees and keep moving forward. Currently, when I hit the arrow key, the character makes the sharp 90 degree turn, but the forward momentum the character previously had takes a second to wear off so the character ends up sliding in the direction he was previously moving a short bit.
The closest example I can think of to visually explain what I'm trying to do is how the character turns sharp in Temple Run. How my game is currently working, if I had the character on a ledge make a sharp left turn, he'd likely keep the original momentum and slide off the edge right after he turns.
Since my character is running on the x/z axis, I'm wondering if there would just be some way to maybe swap the directional velocity/momentum? The speed the character had on the x axis would instantly be switched to the z when it turns and the other would be set to zero. I'm obviously open to any solution that accomplishes what I'm looking for.
I dug into the CharacterMotor class in the first person controller, but have yet to find what part I can tweak to accomplish this.
I'd greatly appreciate any help.
Thank you.
You can try to stop the velocity of the Rigidbody before turning.
this.rigidbody.velocity = Vector3.zero;
this.rigidbody.angularVelocity = Vector3.zero;
If you want the object to continue like it did, you can try playing around with it by saving the current velocity in a variable, setting it to 0, rotate it and then putting back the old velocity (still forward).
If it works with global vectors (so from the point of view of the world, not the object), then you can try negativing the velocity, actually causing it to go 'backwards'. I can't test it for now but either way I think you need to set the velocity to zero first before turning the character.