x


move player to the grabPoint

Hello! I got a great problem with this...Making a grabPoint i got it working, but the player is a little far from grabPoint when grab the point...

I used this to get it on the right height(same of the grabPoint):

transform.position.y = collision.transform.position.y;

Ok, that is working. But Playermodel is a little far from the grabPoint in the axis Z (of the player)... Well i would do the same thing in the Z axis, but it doesnt work.Cause it is about global axis, i need local(some grabPoint would be rotated and that`s the problem)...maybe something about localPosition would help, but not with the same sintax...i tried it before...

[EDIT] I'm using this code:

function OnTriggerEnter(collision : Collider) { 
    if (collision.gameObject.tag == "grabPoint") { 
        grab=true;
        nogravity=true;
        transform.position.y = collision.transform.position.y;
        transform.position.z = collision.transform.position.z;
        transform.eulerAngles.y = collision.transform.eulerAngles.y;
    }
} 

Please help me!!!

Thank you Guys! =D

more ▼

asked Jun 16 '10 at 05:38 PM

Henrique gravatar image

Henrique
93 14 14 17

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

You need to add an offset to the player's new position.

Put a GrabPoint down somewhere, and see exactly where the player should be in relation to it to be visually correct. Then put that value into the var offset : Vector3 below:

transform.position = collision.transform.InverseTransformPoint( offset );

InversetTransformPoint takes rotation into account, so as you rotate a grabPoint, it should rotate the snap-to position properly.

If different GrabPoints can have different offsets, you may need to make offset a member of GrabPoint objects rather than a global / magic number.

more ▼

answered Oct 05 '10 at 07:46 AM

Loius gravatar image

Loius
10.9k 1 12 43

(comments are locked)
10|3000 characters needed characters left

you could just use localPosition instead of position for things you want in local space to an object

alternatively, you could use transform.forward to get the local forward vector of a transform

more ▼

answered Jun 16 '10 at 06:02 PM

Mike 3 gravatar image

Mike 3
30.6k 10 67 254

localPosition isn't working too. With localPosition I got greater problem than before. And transform.forward got the same old problem... It isn't working...=(

Jun 16 '10 at 06:41 PM Henrique

it may be best to post the code you're trying then, otherwise it's just guesswork

Jun 16 '10 at 07:20 PM Mike 3
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x915
x516
x329
x35
x5

asked: Jun 16 '10 at 05:38 PM

Seen: 1364 times

Last Updated: Jun 16 '10 at 08:20 PM