Forum rules - please read before posting.

Flashlight

edited March 2014 in Technical Q&A
Hi guys! i'm kinda new to Unity. I used it a long time ago and just recently got back into it. My main thing is models, sets, players, items, etc so I'm not too familiar with scripting or programming...yet. My question is can I create a flashlight for my player and incorporate it into AC? I've been playing with AC over a week now and have most of the features figured out. I just don't know how to expand what is already there without breaking things. Thanks for any help.:)

Comments

  • I recently created a torch for my player, which is the same idea, right? It's pretty straightforward:

    Once you have the flashlight model, you can create a spotlight and parent it to the flashlight in the editor. Then you just adjust the position, size, etc. of the spotlight to get the light characteristics you want. 

    Incorporating it into AC is pretty straightforward too- If you are making a first-person game without a player character model, you can just parent the flashlight to your place holder character and set the position as desired. 

    If you are making a game with a player character model, Chris has provided an action called Character: Hold Object in which you can attach an object to a hand bone of the character, which needs to be defined in the player script of the character prefab. Depending on how you've set up the skeleton of your character, this can work perfectly, or might need some fine tuning to get the position and rotation of the flashlight right. 

    The best way to do that is to create a cutscene, such as a scene start cutscene, in which the Character: Hold Object action is called and then run the game in a window. Then, if the flashlight is not paired to the hand correctly you can rotate and re-position it while the game is running, copy down the x y z coordinates, end the game, and then add additional Object: Transform actions to your cutscene which move and rotate the flashlight accordingly (the flashlight will need the movable component attached to it).

    That should get the working flashlight parented directly to the desired hand of the character. You can even do some cooler things like run an action which makes the spotlight visible/invisible to simulate turning the flashlight on or off. AC is a very robust tool, and it works quite well with most of Unity's pre-existing functions. Good luck!
  • Thanks for the help. it works great. Hoping I can figure out how to make it follow the cursor as well.
  • Just out of curiosity could someone give me a hint oon how to go about having the flashlight follow the pointer?
  • That'll need a custom script, which converts the mouse position to a point in the scene.  Try playing around with this function. You can get the cross-platform mouse position from PlayerInput's mousePosition variable.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.