So I’m relatively new to the coding world, and thus far most of my experience with game design has been putting the idea for my game together and getting some basic programmers art ready to start coding with.
My question is more design related then anything else. Have a room with objects in it that you can click on to bring up menus, like a computer, a bed, a map and so forth. I have a character in the room that I would like walk to those positions as the UIs come up, to make the room seem like its alive and the character is the one interacting with things.
How would you best handle the movement of the character? Some sort of send message or event driven thing, or a totally different way?
Its a question with many potential answers. I can think of two ways which would be appropriate for you, the difference? One click anywhere, walk to that point. Two, only be able to click specific areas that the player can walk to.
Both ways would involve a collider, placed either over the entire game play area, or over specific spots, bed, counter, etc. when you click, mouse input this area, collider, by using a Raycast() you can gather the position of the click, and in the case of specific placements, the object clicked. This raycast will allow you to gather a position. A point as to where the user clicked. You can now take that position and instruct the player to walk to it.
To walk to an object, in a straight line, I would use MoveTowards() or Translate()
Depending on how intricate your game is, you may want your player to move to and around objects, or something, you can always get more creative, but this is a good basic idea.
I probably should have mentioned it is a 2D game where the maps will simply be side scrolled by spinning the mouse wheel. Basically, for instance, when I click on the computer, the menu will pop up with the computer interface and while you are manipulating it, the character sprite will be moving across the screen to be positioned in front of the camera. Im curious how you would setup to trigger the event to translate and animate the character.
I know that the character script should really only deal with the movement and animation of the character itself, but how would you interface the clicking of objects and setting the desitnation of that character. Thanks!