-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPortal2Trigger.cs
More file actions
36 lines (28 loc) · 1.06 KB
/
Portal2Trigger.cs
File metadata and controls
36 lines (28 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Portal2Trigger : MonoBehaviour
{
public GameObject player;
public GameObject portal1;
public GameObject cam;
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Car")
{
player.transform.position = portal1.transform.position - portal1.transform.forward * 3f;
//Quaternion lookAt = Quaternion.LookRotation(portal2.transform.forward + player.transform.forward, player.transform.up);
Quaternion lookAt = Quaternion.LookRotation(-portal1.transform.forward, Vector3.up);
player.transform.rotation = lookAt;
//player.transform.rotation = portal1.transform.rotation;
RbWork();
}
}
private void RbWork()
{
Rigidbody car = player.GetComponent<Rigidbody>();
float speed = car.velocity.magnitude;
Vector3 velocity = player.transform.forward.normalized * speed;
car.velocity = velocity;
}
}