Log in to reply

[Help] how to Move a vector 3 by pressing a key

  • I'm working on a téléportation script so :
    When my car is in front of another car, this draw a marker ( I know how to do this)
    The problem is how can I move this drawmarker to a left location, right,...
    How can I move my drawmarker by numpad(8= forward, 2 = backward , 4 = left and 6 = right)
    I tried :
    Vehicle car = the nearest vehicle
    Vector3 MoveMaker;
    Float multiplier;
    Running it on Ontick:
    If (game.Iskeypressing(Keys.numpad6)
    MoveMaker = car.position+car.rightvector * multiplier++
    If (game.Iskeypressing(Keys.numpad4)
    MoveMaker = car.position+car.rightvector * multiplier--
    If (game.Iskeypressing(Keys.numpad8)
    MoveMaker = car.position+car.forwardvector * multiplier++
    When I pressing 6 and 4 numpad no problem, the marker is draw , moving from right to left but when I pressing 8 the marker start drawing from car not from last coordination

  • I'm having a hard time understanding what you are trying to accomplish, but i'll answer as best as I can.

    To move back and left, you need to multiply by a negative value:

    For instance: car.RightVector * -multiplier++

    and for back

    car.ForwardVector * -multiplier++

  • Here is a quick script, I just called it Gravity-Gun, for grabbing entities and move their position back and forth using the ForwardVector - aim at an entity, press J, use Numpad 8 and Numpad 2 to move entity further away or closer to you, use the mouse to drag entity around:

        private static bool _isHoldingEntity;
        private static Entity _targetEntity;
        private static float _gravityGunDistanceToTarget = 15.0f;
        private static bool InfiniteAmmo { get; set; }
        public WeaponService()
            Tick += OnTick;
            KeyDown += OnKeyDown;
        private void OnKeyDown(object sender, KeyEventArgs e)
            if (e.KeyCode == Keys.J)
                _targetEntity = Game.Player.TargetedEntity;
                _isHoldingEntity = !_isHoldingEntity;
                if (_targetEntity is Ped ped)
                    if (ped.IsInVehicle())
                        _targetEntity = ped.CurrentVehicle;
            if (_isHoldingEntity && e.KeyCode == Keys.NumPad8)
                _gravityGunDistanceToTarget += 1.0f;
            if (_isHoldingEntity && e.KeyCode == Keys.NumPad2)
                if (_gravityGunDistanceToTarget > 5.0f)
                    _gravityGunDistanceToTarget -= 1.0f;
        private void OnTick(object sender, EventArgs e)
        private void GravityGun(float distance)
            if (!_isHoldingEntity || _targetEntity == null) return;
            var camPos = GameplayCamera.Position + GameplayCamera.ForwardVector * distance;
            camPos.Z += (float)Math.Sin(Game.Player.Character.RotationVelocity.Z - 2.0f);
            _targetEntity.Position = camPos;

    Edit: You can move the key presses to the Tick for a more fluid experience.

Log in to reply

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.