Jump to content

attachElements Problem


Bonsai

Recommended Posts

Hey,

I'm playing around with attaching Elements and I discovered something weird.

This is what I do:

     
local veh = getPedOccupiedVehicle(localPlayer) 
local x, y, z = getElementPosition(veh) 
dummy2 = createObject(1337, x, y, z) 
dummy3 = createObject(1337, 0, 0, 0) 
attachElements(dummy3, veh, 0, 20, 0) 
local x5, y5, z5 = getElementPosition(dummy3) 
--createObject(1337, x5, y5, z5) 
moveObject(dummy2, 3000, x5, y5, z5) 
  

The object is attached to the vehicle, and its right where I want it to be.

But it seems like getElementPosition doesn't return the real values.

My other object "dummy2" doesn't move to where the attached element is.

Also, when I create an object on the positions of the attached one, its at some different position.

Is there some bug on getting positions of attached Elements?

Link to comment
  • Moderators

I don't know if it's a bug, but it would be better if the getElementPosition could return the correct coordinate on attached element relative to the gta world.

If I remember right, it returns the coordinates of the parent that they are attached to.

(I was doing the same with a marker I wanted to place behind the car. The event onMarkerHit was only triggered when I was walking on the middle of the car ...)

As a simple test, you could check if the postition of dummy3 is the same as veh one.

Link to comment

I did some more testing and it seems like it takes some time until the position is updated.

Everything I posted above is done within one function.

But if I attach the element some time earlier, it will return the right values.

That means, I can't change the offset directly in that function.

I'm now attaching the object earlier offset by 1, and just multiply with the desired distance.

Not the best way to do it, but as long as it works.

I would use math functions to get the exact point in front of a vehicle, but it seems to fail for certain rotations.

Link to comment
  • Moderators

Just use that function:

https://wiki.multitheftauto.com/wiki/Get ... ceRotation

(You have to copy and paste the function into your code to be able to use it)

You will call that function with the position x and y of the car, use 0 as angle (streight forward) and as distance well ... all depends of the vehicule, it won't be the same for the limousine and for the golf caddy as you can imagine.

Hope it helps.

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