0

Object look at camera direction (Aventure Camera type)

Razeta 101 1 month ago in Game Creator updated by JSonMac 1 month ago 5

Hello.

I'm kind of new to game creator and unity. I'm trying to make a flashlight object in the hand of my player follow the direction of the camera, like the head or the aiming gun behavior. So far I haven't been able to do it. Any help to solve this? I been using the actions that I can find in the GC framework but no luck. The flashlight is a children of the player model, its attached to the hand.


Thanks.

Unity version:
2019.4.10f1
Game Creator version:
1.1.9

Hey there. Could you give more information about what is the issue? You attached the flashlight to the Player's hand transform right? What's the Player's perspective you want to implement? 1st or 3rd person? If it's 3rd person, the direction of the player is set to movement direction or camera direction? The player will be able to orbit the camera around him with the mouse or it will be stuck at camera direction all the time? What exactly happens when you move the Player's camera? What happens with the flashlight behavior?

Hi.


It's a 3rd person perspective fixed to movement in direction of the camera, not orbital, it's stuck to the camera direction at all times. The flashlight is attached to the left hand. I'm trying to make the flashlight point in the direction of the camera, like the character or the head of the character. So if the camera looks up, the head looks up too. I want the flash light to point up too or in the direction the camera is facing. I been able to attach the flash light to the left hand and it turns around with the player body. But the main problem is when looking up or down, the flashlight is stuck in the same position, it can rotate left or right, but not up or down. I been trying with the look at, but flashlight alway point in the direction of the camera, behind the character and it does not update constantly to move with the camera. For example, I press F for the flashlight to come out and it points in the direction of the camera, but it gets a fixed position until I hide the camera and press F again. Then the new position is set.

Thanks for the reply.

Ok, I got it now. So, I tried something like that for a project of a survival horror game I started (and didn't finished) 6 months ago. 

The thing is you have to look to your character with a different perspective. You don't need the flashlight to rotate, you need the character's left arm to rotate up and down with the camera.

So what I did in my project was to create a empty game object attached to the Player's head and move it to the front of the player. For test purposes I also created a sphere inside this object and inside the sphere a stretched cube along it's Z axis, this way I could see in game mode the object rotating up and down with the Player's head movement. 

After testing and all good, I created a simple script (didn't get GC at that time yet) for the Player's left arm transform rotation in the Z axis to follow that empty object attached to the head and everything worked well. You can try this using a script or using GC actions, the results will be pretty much the same.

If you try this just make sure to use the left arm transform and not the left forearm, cause the second one could result in a really strange animation behavior. In my project I also tried to rotate the Player's torso and the result was also satisfying but in this case I had to decrease the camera's FOV to look better in the 3rd person view.

Hope it helps.

Hi.

Thanks for the reply.

I did went for that approach. But I put the entire flashlight in the head :P because for some reason I could make the flashlight rotate in the Z axis (watch videos, check doc and tutorials) and I couldn't do it. What I did end up doing is using GC to attach the flashlight to the left hand, reach for it and because it was in the head, it moves along side with it. But the animations an position in some instances is not the ideal. It looks like is drifting through the world. I was trying to use that approach of the empty object to but I couldn't make the flashlight follow the object with the GC actions. I don't know how to execute actions like in a loop (update function in unity scripting). 

Thanks for the help.

No problem. I'm at work now but tonight at home I'll try to check my project files to see if I can give you some examples of how to do it using scripts. Hope it helps.