- Home /
Problem with moving platform and gun placment
Hi, I am currently using a script for a moving platform to keep my player on it.
(My player is from the Dastardly Bannana)
the script is
function OnTriggerEnter (other : Collider) { other.transform.parent = gameObject.transform; }
function OnTriggerExit(other : Collider) { other.transform.parent = null; }
While this dose work to keep my player on a platform, All my weapons that are attached to my weapons cam will be displaced are become separated at each mesh.
All I need is a fast and easy fix to this problem. Thank you.
(PS. Please don't just tell me to use the search function because I have and I have been looking for this for about two weeks now.)
(PSS. My platform moves both up, down, and side to side)
Thank you for your help.
I have $$anonymous$$y player then a cam then all of the weapons are children of that cam
you might look at the Dastardly Bannana fps prefab that they have so that you can see basicly what I am dealing with:)
Answer by fherbst · Jun 29, 2010 at 08:17 AM
Parent your weapons to your player (you probably did this already). And you should tell your "OnTriggerEnter" and "Exit" functions to not affect the weapons - if these have colliders for themselves they will get attached to the platform, too. The easiest way to do this would maybe be to assign them to a different layer (e.g. Layer 8 = "PlayerWeapons")
Something like:
function OnTriggerEnter (other : Collider)
{
if(other.gameObject.layer != 8)
other.transform.parent = gameObject.transform;
}
This dose seem to help a little, but my weapons are still not staying where they should be. Got any more ideas? (please say yes, please say yes, please say yes)
agian, you might want to look at the Dastardly bannana project to see what I have, as I have not made many changes yet.
The player collider goes significantly lower than the weapons (which shouldn't have colliders anyway), so I don't think that the weapons would hit the platform.
Answer by twinnightmare · Jun 29, 2010 at 10:57 PM
Give the player gameobject a tag of "player"
var playerObject : GameObject;
function OnTriggerEnter (other : Collider) {
if(other.gameObject.tag == "player")
{
playerObject = other.gameObject;
}
}
function OnTriggerExit(other : Collider) { if(other.gameObject.tag == "player") { playerObject = null; } }
then in your update for your plateform's position check on weather playerObject is null if not then update its position also.
if(playerObject != null)
{
//update player position
}
this won't work because I use animation for my platform, not a script
Your answer
Follow this Question
Related Questions
What is the easiest way to push a character controller with a moving platform? 0 Answers
Problem with moving (animated) platforms. need script to keep player object on 1 Answer
Moving Platform 1 Answer
moving platform jumping and then continuing it's path 0 Answers
Platforms again.. Working but.. 0 Answers