Trying to see flax engine's beauty!

I am just back to flax engine!
It looks like it still has bugs. RotateAround() for example is broken. How ever, I still managed to write out the codes for FPS controls. I am amazed how beautiful Flax engine’s 3D graphics are yet!
I want devs to fix some broken parts of the engine a bit. It’s cool! Multiplayer support was added and it made me to test it out again! Keep the job up flax devs :love_you_gesture: :love_you_gesture: :love_you_gesture:

1 Like

What is broken in RotateAround()? Works for me just fine.

I don’t know why it happened. But it doesn’t rotates the camera (X) and CharacterController (Y) with Input.GetAxis(). No compilation error, but things were buggy.
Except I used this:


            // Rotation
            Quaternion playerRot = controller.LocalOrientation;
            Quaternion camRot = camera.LocalOrientation;

            playerRot = Quaternion.Euler(0, playerRot.EulerAngles.Y + Input.GetAxis("Mouse X"), 0);
            camRot = Quaternion.Euler(camRot.EulerAngles.X + Input.GetAxis("Mouse Y"), 0, 0);

            controller.LocalOrientation = playerRot;
            camera.LocalOrientation = camRot;

After hearing that your code works, it’s making me to try out the RotateAround next time.
Not kidding, but I sometimes feel like my PC is hacked. Cause sometimes, things don’t go as I expect. lol but not so funny though!

I assume you are using the code in OnUpdate()? Have you tried multiplying your input by Time.DeltaTime and then also multiply by some rotation speed float that you could set in the editor? It could make your player rotate much smoother.

I had putted it in OnUpdate() as I remember. And Input was responding glitchy. As it was responding through frames, I assume it was OnUpdate(). Okay something like,
it either rotating full 180 degrees or comes back to 0 degrees.
Now I believe that I was putting wrong Vectors on the function. But I putten the this.Actor.Transform.Up (like Unity’s transform.up). Okay let me directly check and reply the results. I’ll redo it in another project.

Okay this is the code. I still have the problem. Let me modify more. Well, how did you wrote the code???

using System;
using System.Collections.Generic;
using FlaxEngine;

namespace Game
{
    /// <summary>
    /// CharacterControllerExp Script.
    /// </summary>
    public class CharacterControllerExp : Script
    {
        /// <inheritdoc/>
        [Serialize, ShowInEditor]
        Actor cam;

        public override void OnStart()
        {
            // Here you can add code that needs to be called when script is created, just before the first game update
        }
        
        /// <inheritdoc/>
        public override void OnEnable()
        {
            // Here you can add code that needs to be called when script is enabled (eg. register for events)
        }

        /// <inheritdoc/>
        public override void OnDisable()
        {
            // Here you can add code that needs to be called when script is disabled (eg. unregister from events)
        }

        /// <inheritdoc/>
        public override void OnUpdate()
        {
            // Here you can add code that needs to be called every frame
            Actor.RotateAround(this.Actor.Position, this.Actor.Transform.Up, Input.GetAxis("Mouse X"));
            cam.RotateAround(this.Actor.Position, cam.Transform.Right, Input.GetAxis("Mouse Y"));
        }
    }
}

Still not working.

Let me see if I can upload video on the matter.

It looks like I can’t upload video on forum.
But I don’t have idea why the RotateAround() not working properly yet.

I’m fairly certain that RotateAround() does not additively change the rotation. Try this instead:

Actor.RotateAround(Actor.Position, Transform.Up, Input.MousePosition.X);
cam.RotateAround(Actor.Position, Transform.Right, Input.MousePosition.Y);

P.S.: this is not required when referring to an Actor. :+1:

1 Like

Seems wrong to just leave this thread dirty like this.
I don’t see the OP doing cursor locks but it’s bound to go there eventually.
Just go for the CharacterControllerPro scripts and hit the ground running.
But for something much simpler, give this a sniff.

using FlaxEngine;

namespace Game
{
    // Actor Parenting for this use case
    //
    // Actor (capsule mesh) (added script here)
    //     |
    //     |__ Character Controller (adjusted to default capsule size)
    //     |
    //     |__ Camera (position offset back/up {0, 120, -90} from parent origin)
    //
    // note: I also like to position my origins at the bottom
    //       which you would normally get from imported character models
    //

 
    public class Rotator : Script
    {
        public Camera cam;
        public Vector2 sensitivity = new Vector2(1.0f, 0.4f);

        private float _rotX;
        private Vector3 _offset = new Vector3(0, 75, 0); // start at Actor head height


        public override void OnEnable()
        {
            Screen.CursorLock = CursorLockMode.Locked; // put us somewhere more appropriate 
            Screen.CursorVisible = false;                                          //
        }

        public override void OnUpdate()
        {
            _rotX += Input.GetAxis("Mouse X") * sensitivity.X;     // Input.MousePositionDelta returns zero in locked cursor state 
            _offset.Y -= Input.GetAxis("Mouse Y") * sensitivity.Y; // negate for reverse look
            _offset.Y = Mathf.Clamp(_offset.Y, -75, 200);

            Actor.RotateAround(Actor.Position, Transform.Up, _rotX);
            //Actor.RotateAround(Actor.Position, Transform.Up, Input.MousePosition.X); // avoid some arbitrary starting rotation
            //cam.RotateAround(Actor.Position, Transform.Right, Input.MousePosition.Y); // sure, if you want to get your freak on :)
            //cam.RotateAround(Actor.Position, Transform.Right, Input.MousePositionDelta.Y*sensitivity); // still kinda lame
            cam.LookAt(Actor.Position + _offset);

            // now get inventive with the over the shoulder action on your own
        }

        public override void OnDisable()
        {
            Screen.CursorLock = CursorLockMode.None; // these guys go too
            Screen.CursorVisible = true;                                       //
        }

    }

}

references:
I made a third-person movement tutorial!
Free and Open Source Character Controller Pro for Flax Engine!

similar assumptions:
Transform.RotateAround() how to implement it on Flax Engine

1 Like

Ah, late reply from me.
I guess your code would work. I am a copy, paste and learn guy. So if your code works after my copy-paste, than I learn that function.
Spectrix, you sound like experienced developer. Actually are ya???

No thanks but I appreciate! Let me create my own :love_you_gesture: My code would get messed up mayba…
Don’t mind on CharacterControllerPro but was something interesting of it’s C# side of codes for Flax Engine.

I’m not a professional developer, but I’ve been programming for nearly 8 years at this point.

1 Like