I have a serious problem with my game project. I have always used my own scripts so far, but I cannot put the feature I want to add to the game by myself.
I will show what I want to do with an example video.
When you move your joystick, do you want to stop looking at the lockon target?
or
When you move your joystick, do you want to change the offset between the lockon target and the crosshair?
or
Do you want to the joystick to only control the position of the camera around your car, and the lockon target controls the rotation of the vcam? Something like on the attached image?
Hi @gaborkb
yes, when I move my joystick, I want to change the offset between the locked target and the crosshair. When the target enemy reaches the dead zone on the screen, the lock will be disabled.
My player should always be visible on the screen.
The left joystick is about controlling my car controller. the right joystick is for orbiting around my car (my player) and searching for enemies in the detectable screen area. If there is any target in the area, lock onto it.
Another important part here is that even when lock-on is active, I should be able to use my orbit operation around my player comfortably. In this way, even when the target enemy is lock-on (but not focused on the crosshair), I can focus the crosshair directly on the enemy with the help of the joystick and shoot him.
In short, I am trying to create a targeting helper system. but never, never focus enemy directly on the crosshairs in the center of the screen. offset must be maintained at all times. In this way, players cannot easily destroy their enemies.
They will have to use the rotating joystick and make an effort to focus directly on the enemy via crosshair. I’m just trying to make things a little easier. but nothing more.
In the video, you are using freelook. With freelook, you can modify the Tracked Object Offset (under Aim, and note, you have 3 different rigs in a freelook, so you will possibly need to modify all 3). Hook up the Tracked Object Offset parameters with one your joysticks.
You will possibly want to restrict the Tracked Object Offset within some bounds, so the offset does not become too big.
But when I use any lock-on system, will I need to use a targetgroup?
Will I be able to offset when lock-on is active?
Will my main player always stay in the same pivot position on the camera?
I haven’t been very successful with cinemachine. can you send me a basic demo for understand?
If you want to CM to try to frame your player and lock-on enemies at the same time, then yes. In this case, your Freelook’s LookAt target is always a TargetGroup. This TargetGroup always contains the player. When you “lock on” to an enemy, you add the enemy transform to the TargetGroup. When you no longer “lock on”, then you remove the enemy transform from the TargetGroup.
Note, there are cases when the cinemachine cannot frame the player and the enemy at the same time, because it would need to move the vcam, not just rotate it. For example, when you have the enemy, camera, and player on a line in this order.
Yes, you can dynamically change the Tracked Object Offset anytime.
Yes, the pivot is not going to change if you only modify the LookAt target (or the TargetGroup it is looking at) or the Tracked Object Offset.
If you send me your project, then I could set up something for you.
I’ve been working for about 4 hours, but I couldn’t create a scene similar to what I said.
When I create a target group, the camera leaves the pivot position in its player and moves to a new center centering on both players. I am currently not including cinemachine in my own project. The video I sent you was not my own game, it was an image from an example game that I was inspired by.
I’m currently working in cinemachine’s sample Free Look character scene in an empty project file. but I couldn’t make any progress. I didn’t include it directly because my own game is live and in a stable project file.
I am sending you my files in cinemachine’s sample project.
You said that you want to control the camera position with a joystick (pivot is the player, so you move the camera on a circle/sphere). If you move the camera between the player and the target, there is no way for the camera to frame both without moving the camera.
See the attached image, what should the camera do in this case?
Do you have more recordings of how this system works? What happens if you rotate away? Does the proximity of enemy only counts when it is visible on the screen?
Have a look at the DualTarget example scene (you’ll need Cinemachine 2.6 for this example).
To get something close to what you’d like modify DualTarget scene like this:
1.
Change Composer to Hard Look At on the CM Dual Target virtual camera. See the attached image.
Change the Soft Zone parameters to 0 on Framing Transposer.
Now you have the same camera behaviour as you want without automatically locking on targets.
If you want to lock on targets, you will have to modify the AimTarget Moved by Mouse and its script. A possible quick solution would be to do the following when you lock on:
Disable the Move Aim Target script on AimTarget Moved by Mouse.
Parent AimTarget Moved by Mouse to the enemy you want to lock on.
Write a script that will move the now parented AimTarget Moved by Mouse within its local space (i.e. translate it on x,y,z locally).