Forum rules - please read before posting.

Rotate player in the mouse direction

Good morning, I'm trying to create a movement so that when the player picks up a bow, they can turn their body with the mouse and walk in the direction of the bow ( Watch the attached video) . I downloaded the combat system, but I don't see any weapons or anything in that example. I don't know if I'm doing something wrong or if the example isn't accurate. Any help, please?
Thanks in advance

https://files.fm/u/cguupmm3vd

Comments

  • Welcome to the community, @Abbey.

    To clarify with the combat example: this is more intended as a demonstration of how AC can be extended through scripting, rather than an add-on feature that allows for combat.

    I'm not entirely clear your intent from the clip - the Player appears to turn to face the mouse. What is the difference in the way it currently works, vs the way it should?

  • What I want is to make a movement like the one in the video, so that it walks normally when it's not carrying the weapon, and then turns and walks in the direction of the mouse, like in the video. The video is an example of what I want to do; I'm sorry I didn't explain myself well enough. Could you please provide an example? I can pay for that.

    In the combat system example, I can only walk, grab the key, and exit through the door. Nothing else appears. Maybe I'm doing something wrong.

  • edited April 7

    To be clear: AC is not a combat engine. The example is just to demonstrate that AC can be extended in such a way through scripting - not a demonstration of built-in features of this type of game.

    If you are looking to make a combat game with minimal to no coding, I would recommend looking at a separate asset that's dedicated to that kind of gameplay.

    To have the Player face the mouse cursor when a given item is selected, you can assign the Player's DirectMovementTargetLock property to a Transform that follows the mouse position.

    This would be as part of a custom script that:

    1. Positions the GameObject it is attached to to the cursor position in 3D space
    2. Detects if a given item, referenced by its ID number is selected, and if so:
    3. Forces the Player to face its GameObject

    Something along these lines, attached to an empty GameObject, should do it:

    using UnityEngine;
    using AC;
    
    public class PlayerFollowCursor : MonoBehaviour
    {
    
        public int itemID;
    
        void OnEnable ()
        {
            EventManager.OnInventorySelect += OnInventorySelect;
            EventManager.OnInventoryDeselect += OnInventoryDeselect;
        }
    
        void OnDisable ()
        {
            EventManager.OnInventorySelect -= OnInventorySelect;
            EventManager.OnInventoryDeselect -= OnInventoryDeselect;
        }
    
        void OnInventorySelect (InvItem invItem)
        {
            // Lock the Player's facing direction to this object
            if (invItem.id == itemID)
                KickStarter.player.DirectMovementTargetLock = transform;
        }
    
        void OnInventoryDeselect (InvItem invItem)
        {
            // Unlock the Player's facing direction
            KickStarter.player.DirectMovementTargetLock = null;
        }
    
        void Update ()
        {
            // Move this object to the cursor
            Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast (ray, out hit))
            {
                transform.position = hit.point;
            }
        }
    
    }
    
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.