Jump to content

Motorcycles and bicycles setElementPosition bug


relvarten

Recommended Posts

This is my code:

        setElementPosition(playervehicle, 2263.8660, 1398.6057, 43.5252)
        -- setElementAngularVelocity(playervehicle, 0, 0, 0)
        -- setElementVelocity(playervehicle, 0, 0, 0)

Teleport works great for any type of vehicle, except motorcycles and bicycles. When the teleportation distance is more than 100 meters, then when teleporting, the two-wheeled transport scatters in all directions, while not sparing the driver himself, first throwing him out. The greater the distance, the more chaotic.

I tried everything: all combinations of setElementVelocity, setElementAngularVelocity, removePedFromVehicle, warpPedIntoVehicle, even used timers in an attempt to make such a crutch. The additional teleport of the driver himself does not help either.

The only similar thing I found on the Internet is a bug report by ArranTuna ( https://github.com/multitheftauto/mtasa-blue/issues/529 ). It mentions that there is a fix using setElementGravity, but does not specify how.

Link to comment

Update: there is no bug when teleporting, if before the teleport itself (in the same function) destroy the old one vehicle and create a new one. It is strange that this works, because it is not clear what is the difference between this method, and a complete reset of all accelerations of the vehicle and the player (not to mention that in addition I do the removing of the player and warp him back).

Link to comment
5 hours ago, relvarten said:

Update: there is no bug when teleporting, if before the teleport itself (in the same function) destroy the old one vehicle and create a new one. It is strange that this works, because it is not clear what is the difference between this method, and a complete reset of all accelerations of the vehicle and the player (not to mention that in addition I do the removing of the player and warp him back).

I managed to avoid the bug by using a timer before transporting the vehicle.
First I remove the player from the vehicle and transport him to the position, then with a timer I transport the vehicle

addCommandHandler("tp", 
   function(player)
      local vehicle = player.vehicle 
      if vehicle then 
         player:removeFromVehicle()
         player:setPosition(1660.8480224609, -2629.8156738281, 13.54687)
         Timer(function()
            vehicle:setPosition(1660.8480224609, -2629.8156738281, 13.54687)
            player:warpIntoVehicle(vehicle)
         end, 50, 1)
      end 
   end 
 )

 

Edited by alex17"
  • Thanks 1
Link to comment
16 hours ago, alex17" said:

I managed to avoid the bug by using a timer before transporting the vehicle.
First I remove the player from the vehicle and transport him to the position, then with a timer I transport the vehicle

addCommandHandler("tp", 
   function(player)
      local vehicle = player.vehicle 
      if vehicle then 
         player:removeFromVehicle()
         player:setPosition(1660.8480224609, -2629.8156738281, 13.54687)
         Timer(function()
            vehicle:setPosition(1660.8480224609, -2629.8156738281, 13.54687)
            player:warpIntoVehicle(vehicle)
         end, 50, 1)
      end 
   end 
 )

 

I will try it at evening. Hope it will work. Looks like yes.

However, I cannot understand. Version 1.5.9, and the behavior of motorcycles in some situations is still "outlawed" ... and you have to use crutches for the most ordinary teleport...

Link to comment

Using timer, as suggested by alex17" is not a bad option, but it works average. I "solved" the problem with resetting the tilt of the motorcycle when teleporting in my own way. It turned out that it is best to recreate the car through CloneElement. I would give the script that I wrote, but there too many confusing functions. But I will explain In a simple way, how should a working teleport look like, in which motorcycles will not throw themselves and the player when teleporting from far distance:

1. Write down all the occupants, so that later we can return them to the cloned transport.

2. Clone the transport.

3. Destroy the old transport.

4. Return the occupants back.

5. Teleport the cloned transport and set the necessary rotations and accelerations for it.

Yes, you will have to do a lot of things if your mod has grown (for example, if some variables are assigned to vehicle ID, then after the teleport there should be a function to find and replace the assigned data with the ID of the cloned vehicle).

However, I am more than satisfied. There are no delays, it teleports perfectly. In the absence of the ability to reset the tilt of the motorcycle, this is the best option that I could think of and implement.

 

P.S. Even with the crutches that you have to use in the MTA, which is still a pretty green mod, the MTA has a lot of potential in my opinion.

P.P.S. Also, sorry for broken english. I do use google translate to communicate here. But this very line i did write without google translate. :)

Link to comment
On 17/02/2023 at 05:50, relvarten said:

Just as an addendum (probably off topic): motorcycles and bicycles in the MTA are generally "unique". Even setElementFrozen doesn't fully work on them - you can still tilt left and right

I guess motorcycles and bicycles have some tilt property that is separate from rotation and changes as you steer. Maybe it's just visual. Maybe it's not even a property on its own, but rather one of the effects of steering state. And I also assume that setElementFrozen only locks position, rotation and velocity - in which case that tilting property would remain unaffected.

A long time ago, I tried making a CLEO script that records the player's driving route by writing the vehicle's position, rotation and velocity to a file in short intervals, and then plays it. I wasn't able to get it to look properly on bikes, because the bike wasn't tilting to the side it was steering during the playback - to the contrary, it was slightly steering to the opposite side. I did realize it was because of lack of control states, but didn't know how to overcome that problem. Now that you pointed out the behavior of setElementFrozen, it looks related. Interesting to find out many years later :)

  • Like 1
Link to comment

You can use "setPedCanBeKnockedOffBike" function but its server sided, also there is no such function "setElementGravity" at least not on MTA there are setVehicleGravity and setPedGravity

server-side:

function teleportVehicle(player, command, x, y, z)
    if not isPedInVehicle(player) then
        outputChatBox("You must be in a vehicle to use this command.", player, 255, 0, 0)
        return
    end
    local playervehicle = getPedOccupiedVehicle(player)
    if not x or not y or not z then
        outputChatBox("Usage: /tp [X] [Y] [Z]", player, 255, 0, 0)
        return
    end
    x = tonumber(x)
    y = tonumber(y)
    z = tonumber(z)
    if not x or not y or not z then
        outputChatBox("Invalid coordinates.", player, 255, 0, 0)
        return
    end
    triggerClientEvent(player, "onClientTeleportVehicle", player, x, y, z)
    outputChatBox("Vehicle teleported to coordinates: "..x..", "..y..", "..z, player, 0, 255, 0)
end
addCommandHandler("tp", teleportVehicle)

client-side:

function tp(x, y, z)
    local player = getLocalPlayer()
    local playervehicle = getPedOccupiedVehicle(player)
    setElementPosition(playervehicle, x, y, z)
    setPedCanBeKnockedOffBike(player, false)
    setTimer(function() setPedCanBeKnockedOffBike(player, true) end, 1000, 1)
end
addEvent("onClientTeleportVehicle", true)
addEventHandler("onClientTeleportVehicle", root, teleportVehicle)

don't mind the command and all the error handling I've built it to try it tho, I wanted to see if to set its Gravity will fix it :)

  • Like 1
Link to comment

FLUSHBICEPS , I appreciate your help. Truly :)

Unfortunately, this method doesn't work. And my mistake - I formulated the problem incorrectly. Falling off a motorcycle is not the problem. This is just a consequence of that problem.

Take your script as an example. It works well, like all other teleporters, but only from a short distance. The further you drive away, the more chaotic the teleport.

You can, of course, do repeating the command until you find yourself in place. But...

Nevertheless, I will continue to use vehicle cloning, because, as I understand it, there are no other options to reset the motorcycle tilt.

Edited by relvarten
Semantic errors
Link to comment

Already. The motorcycle only sways in all directions, everything is fine with the camera. The problem is tilt itself. Tilt, as it were, destabilizes the synchronization between the driver and the motorcycle, and therefore at the exit we can easily get a motorcycle doing somersaults three times, and at the same time it will be 50 meters from the teleport point.

By the way, I tried to put Ped in the passenger seat, and then make a teleport with him. Everything went great. So we can be sure, that the problem is only in the tilt of the driver. And even if you are not tilted during the teleport, there is always a basic tilt (when CJ stands with one foot on the ground). In short, there is something like unaccounted rotation Y for the player in MTA, instead of assigning it to motorcycles.

  • Like 1
Link to comment

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...