- Home /
Player jumping into object
Hi, I have search unity anwers for different ways to implement that the player can jump into objects and control them (like GTA with the cars). I'm trying to parent the player to the car, but don't know if I'm on the right way. can someone give me some directions? here is the code, I put this on a trigger close to the object:
using UnityEngine;
using System.Collections;
public class observtrigger : MonoBehaviour {
public Transform player = player;
public Transform observer = observer;
//public Rigidbody observer;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerStay(Collider other)
{
if(Input.GetKeyDown("e"))
{
player.parent = observer;
//HingeJoint.connectedBody = observer;
}
}
as you can see, I am using C Sharp
I don't know about this line
public Transform player = player;
If it weren't for Unity's serialization, this would always assign null. Better just to name it without assigning anything at that point.
Answer by Caiuse · Nov 15, 2011 at 11:32 AM
Can't see what the problem your having is?
try using a boolean?
var nextToCar : boolean;
function Update(){
if(Input.GetKeyDown("space")){
if(nextToCar){
player.transform.parent = car.transform;
} else {
print("not next to car");
}
}
}
function OnTriggerStay(other : Collider){
if(other.collider.gameObject.CompareTag("Car")
nextToCar = true;
}
Great! now the player is a parent to the "car", now I only need to make controlls for the car. Thanks! : D
Your answer
Follow this Question
Related Questions
How to make camera position relative to a specific target. 1 Answer
Is it bad to have many object in the scene with Lateupdate function checking player position 1 Answer
my ball sometimes jumps higher or sometimes not 2 Answers
Player hanging on objects. 0 Answers
Java script for unity 3d game player going into car? 1 Answer