Jump to content

How do I make the person move relative to the camera and not the axis?


Recommended Posts

Posted

How do I do this? Right now the noclip moves over the axis but as soon as include Z axis he goes all over the place:

 

using RAGE;
using System;
using System.Collections.Generic;
using System.Text;

namespace SOCRPClient
{
    internal class NoClip : Events.Script
    {
        Vector3 position = new Vector3(0, 0, 0);
        Vector3 rotation = new Vector3(0, 0, 0);
        Vector3 direction;
        int camera = 0;
        bool isOn = false;
        RAGE.Elements.Player localPlayer = RAGE.Elements.Player.LocalPlayer;
        float f = 1f, l = 1.0f, h = 1.0f;
        bool updated = false;

        public NoClip()
        {
            Events.Tick += Tick;
            Events.Add("NoClip.Toggle", ToggleNoClip);

            
            rotation = localPlayer.GetRotation(2);

            camera = RAGE.Game.Cam.CreateCameraWithParams(
                    RAGE.Game.Misc.GetHashKey("DEFAULT_SCRIPTED_CAMERA"),
                    position.X, position.Y, position.Z,
                    rotation.X, rotation.Y, rotation.Z,
                    70.0f, true, 2);
            localPlayer.SetAlpha(0, true);
            localPlayer.SetInvincible(true);
            RAGE.Game.Cam.SetCamActive(camera, true);
            RAGE.Game.Cam.RenderScriptCams(true, false, 0, false, true, 0);
            
        }

        public void ToggleNoClip(object[] args)
        {
            isOn = !isOn;
        }

        public void Tick(List<Events.TickNametagData> nametags)
        {
            if (!isOn) return;
            direction = RAGE.Game.Cam.GetCamRot(camera, 2);

            var aadf = RAGE.Game.Pad.GetDisabledControlNormal(7, 1);

            var pitch = direction.X;
            var yaw = direction.Y;

            position = localPlayer.Position;
            Chat.Output($"{direction.X}, {direction.Y}, {direction.Z}");

            if (RAGE.Game.Pad.IsControlPressed(0, 32)) // W
            {
                position.X += direction.X * 1.0f;
                position.Y += direction.Y * 2f;
            }
            else if (RAGE.Game.Pad.IsControlPressed(0, 33)) //S
            {
                position.X -= direction.X * 2f;
                position.Y -= direction.Y * 2f;
                updated = true;
            }
            else f = 2.0f;

            if (RAGE.Game.Pad.IsControlPressed(0, 34)) // A
            {
                position.X += (-direction.Y) * 2f;
                position.Y += direction.X * 2f;
                updated = true;
            }
            else if (RAGE.Game.Pad.IsControlPressed(0, 35)) // D
            {
                position.X -= (-direction.Y) * 2f;
                position.Y -= direction.X * 2f;
                updated = true;
            }
            else l = 2.0f;
    
            if (RAGE.Game.Pad.IsControlPressed(0, 321)) // Space
            {
                position.Z += h * 2f;
                updated = true;
            }
            else if (RAGE.Game.Pad.IsControlPressed(0, 326)) // LCtrl
            {
                position.Z -= h * 2f;
                updated = true;
            }
            else h = 2.0f;

            if(updated)
            {
                RAGE.Elements.Player.LocalPlayer.SetCoordsNoOffset(position.X, position.Y, position.Z, false, false, false);
                RAGE.Elements.Player.LocalPlayer.SetRotation(direction.X, direction.Y, direction.Z, 2, true);
            }
        }
    }
}

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...