Adding a Vector to a position
Hi, I made a respawn system for a simple roll-a-ball game, but, every time the ball teleports back to a checkpoint, the ball clips through the floor. I want to modify the vector the script reads from by adding another vector to prevent clipping. What this script does is reads the the checkpoint object and sets the position of it as the respawn point. It is just a bit too short and needs a vector added to the vertical axis to prevent the ball from falling through as soon as it respawns.
Here's the script and thanks in advance.
using UnityEngine;
using System.Collections;
public class checkPoint : MonoBehaviour {
private GameObject global;
private GameObject player;
void OnTriggerEnter(Collider player)
{
if(player.tag == "Player")
{
player.GetComponent<playerCheck>().checkPos = transform.position;
}
}
}
To be a little more specific, how do I add a vector to "transform.position"? (if that is possible)
Answer by SarperS · Jun 18, 2016 at 10:25 AM
using UnityEngine;
using System.Collections;
public class checkPoint : MonoBehaviour {
public Vector3 offset;
private GameObject global;
private GameObject player;
void OnTriggerEnter(Collider player) {
if(player.tag == "Player") player.GetComponent<playerCheck>().checkPos = transform.position + offset;
}
}
Answer by DRAmos97 · Jun 19, 2016 at 10:29 PM
Thanks, I was having trouble implementing it, but I figured something out.
using UnityEngine;
using System.Collections;
public class deathPit : MonoBehaviour {
void OnTriggerEnter(Collider fall)
{
if (fall.tag == "Player")
{
fall.transform.position = fall.GetComponent<playerCheck>().checkPos + new Vector3(0,1,0);
GameObject.Find("Justifier_01").GetComponent<Rigidbody>().velocity = Vector3.zero;
GameObject.Find("Justifier_01").GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612083159im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Creating a new vector3 2 Answers
Teleport camera to where is pointing at 3 Answers
How to teleport an object to 1 of 8 possible locations on collision? 1 Answer
+= operator on transform.localPosition results in random values 1 Answer
Find distance from camera perpendicularly to targets transform.right. 1 Answer