x


How to get a Character to move with a moving platform ?

I've been trying to get my character to move along with my moving platform (like when i jump unto the platform it carries me long with it), but so far have been unable to do so.
I have a character with CharacterController, it has also been tagged by 'Player'.
My moving platform has a 'Rigidbody' attached to it, a 'Configurable Joint'and a 'Box Collider'. The platform is tagged with 'JumpPad5'.
This is the script attached to my moving platform:

var targetA : GameObject;
var targetB : GameObject;

var speed : float = 0.1;

function FixedUpdate ()
{
var weight = Mathf.Cos(Time.time * speed * 2 * Mathf.PI) * 0.5 + 0.5; transform.position = targetA.transform.position * weight + targetB.transform.position * (1-weight);
}

So if anyone can help me, pleaso do.

more ▼

asked Feb 24 '10 at 10:28 PM

CracksisT gravatar image

CracksisT
2 1 1 1

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

2 answers: sort voted first

There are already multiple answers for this question on the site. Please use the search option for next time. These Answers should get you started. If questions remain after reading those, feel free to post them.

Answer1

Answer2

Answer3

more ▼

answered Feb 24 '10 at 10:31 PM

Sebas gravatar image

Sebas
4.1k 12 18 45

I already checked those answers and I couldn't get it working with my character. That's why I asked the question myself, providing my own information, hoping that would help.

Feb 24 '10 at 10:38 PM CracksisT

Not sure which option would be best, but I'd try to implement those other solutions first and ask questions in those answers via comments. What exactly didn't work when you tried those solutions? There are multiple answers provided, so it's not very likely that somebody is going to take the time and come up with something totally new here. Was the joint a problem? Try to break your platform/project down so you can get it to work with one of the provided solutions and so that you understand how they got it working, then expand to suit your needs. But that's just a thought.

Feb 24 '10 at 11:08 PM Sebas

When I use 'Answer1' I get an error saying: Assets/CharStickPlatform.js(26,44): BCE0020: An instance of type 'FPSWalker' is required to access non static member 'speed'. How do I solve this?

Apr 03 '10 at 06:35 PM CracksisT

Do you use the Character Controller with the FPSWalker script? The script for Answer1 requires you to use the FPSWalker script, because it refers to its variable speed.

Apr 04 '10 at 12:02 AM Sebas

No I probably didn't cause I don't know how to do this. (But I'm not trying to make a FPS, I'm trying to make a 3rd person game.)

Apr 17 '10 at 05:17 PM CracksisT
(comments are locked)
10|3000 characters needed characters left

Can't you make the player a child to the platform with On trigger stay/exit events? That way the player will move, rotate, etc with the platforms movements AND speed, while still having their own controls.

 function OnTriggerStay(other:Collider){

           if(other.gameObject.tag == "platform"){
           transform.parent = other.transform;

       }
    }

function OnTriggerExit(other:Collider){
    if(other.gameObject.tag == "platform"){
         transform.parent = null;

       }
    }  
more ▼

answered Nov 05 '11 at 07:37 PM

superventure gravatar image

superventure
670 44 54 63

(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:

x2584
x1948
x1081
x149
x18

asked: Feb 24 '10 at 10:28 PM

Seen: 4275 times

Last Updated: Oct 26 '12 at 03:20 PM