Hi all!
I want in my game to be able to interact with the object. For this I made different animations of interactions. For example opening all sorts of cabinets, chests and other things. Animation interaction, I made directly in front of the player and it looks correct only whenpersona standing in a certain place from the object and the camera looks directly at the object. I wrote code for it, but it doesn’t work correctly. If the character looked up or down during the interaction, then after pulling to the object and turning, he will also look up or down, and this, as you understand, breaks the whole idea, because the interaction animation is played in a completely wrong place, and it just looks terrible.
I’d love it if anyone could share the code to rotate the character strictly to the center of the object.
Thanks for your help!
This is my code
1 Like
Correct me where I’m wrong, but I think you need the character in front of the object, facing it.
So that’s two things. Position and rotation.
Rather than trying to do it smoothly for now, just try putting them in the right place, facing the right way.
So that’s going to be ‘set actor location’ and ‘look at rotation’ with ‘set control rotation’.
I would be eternally grateful if you could share the code. I haven’t been programming that long, and I probably don’t quite understand what I’m doing wrong.
To get them directly in front of the object, you can just extend the forward vector of the object ( assuming you don’t have a weird object orientation ). If you do have a strange orientation, you can use an arrow component.
I have a cube like this, notice the forward vector
You probably have some way to get a reference to the actor you’re going to interact with. My character does that with a line trace ( it doesn’t matter ). I will deliberately stand to one side of the cube, and ask to interact.
This code then puts me directly in front of the cube, facing it
Like this ( just changed the code, it might be a mix of actor and control rotation )
Tell me if you don’t get part of it.
Hi! Thank you so much for all your help!
I really have an FPS character, does it matter for the code?
After triggering this code, my character moves somewhere underground. I’m throwing here the code I wrote, did I make a mistake somewhere?
I used distance value = 150
Ah… I assumed you were using 3rd person, because of talking about animations.
Here’s the start of the code for 1st
1 Like
Thank you!
But it still doesn’t rotate exactly centered.
If you shoot at any of the corners of the object, the character is not rotated strictly in the center, but with various deviations. Is there not some solution to make him look exactly in the center?
I am very grateful to you for wasting your time on me.
Can you show where the pivot point is for that door mesh? ( both the meshes probably ).
Have you tried it with a cube?
1 Like
For it to work with meshes, in object mode ( not world ), the X should be pointing forward
Maybe try a cube for now…
Yes, I tried shooting the cube, but after rotation also looks a little higher off center
i think, after rotation my character look in center, but in screen center
It looks pretty good to me. You’re aiming high on the corner, and it’s just getting centered, no?
( At the moment, the code only deals with Z, so it won’t correct your upwards aim )
Screen center, yes it would. You didn’t say anything about a targeting system
At any rate, this is still correct, I think…
Yes, I am an expert at getting my thoughts right. )))
And how i can make it to look at the center of the object?
it is difficult?
Can you show me the pivot? ( you still haven’t )
Is it a blueprint?
Object pivot?
If i need to change all pivots of objects strictly to the center, I will do it.
Yes. it is blueprint
The main thing for me is to at least make the right turn on a simple object, and then I will make all the objects in the same
Blueprint, ok, different method…
Some bits are easier, others a bit harder.
At least with a blueprint you can put a component in, saying where you want the character to stand while interacting.
You can do it like this
And put it facing the BP, like you want the player to stand
Now you need the door to tell the player about this when they interact. For now, we’ll do it with casting, unless you already know about interfaces.
So, now, the player comes up to the door and
1 Like
The first thing I did was to study the interfaces.
1 Like
If you get it working with casting, then I’ll show you the interface. ( That may be tomorrow… )
Thank you so much for your help!
Have a great evening!
The character turns and looks at the center of the screen, but not at the center of the object. Can I make some kind of pointer on the object where to turn the player’s camera?
Like an arrow or invisible sphere?
It seems to me that all of our code rotates the character’s capsule, not his camera. And for me, it is important to rotate the camera to the center of the object. To then trigger the interaction animation.
And to position it correctly, the character has to stand in the right place and look exactly at the center of the object.