Untitled
unknown
plain_text
a year ago
2.5 kB
10
Indexable
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class PlayerController : MonoBehaviour
{
public float moveSpeed = 8f;
public float jumpForce = 8f;
private Rigidbody rb;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
private void Update()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
Vector3 move = (transform.forward * v + transform.right * h) * moveSpeed;
Vector3 vel = rb.velocity;
rb.velocity = new Vector3(move.x, vel.y, move.z);
if (Input.GetKeyDown(KeyCode.Space))
{
rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
}
}
}
using UnityEngine;
public class WebSwinger : MonoBehaviour
{
public LineRenderer webLine;
public LayerMask grappleMask;
public float maxDistance = 50f;
public float swingForce = 20f;
private SpringJoint joint;
private Vector3 swingPoint;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.forward, out hit, maxDistance, grappleMask))
{
swingPoint = hit.point;
joint = gameObject.AddComponent<SpringJoint>();
joint.autoConfigureConnectedAnchor = false;
joint.connectedAnchor = swingPoint;
float dist = Vector3.Distance(transform.position, swingPoint);
joint.maxDistance = dist * 0.8f;
joint.minDistance = dist * 0.25f;
joint.spring = swingForce;
joint.damper = 7f;
joint.massScale = 4.5f;
webLine.positionCount = 2;
}
}
if (Input.GetMouseButtonUp(0) && joint)
{
Destroy(joint);
webLine.positionCount = 0;
}
if (joint)
{
webLine.SetPosition(0, transform.position);
webLine.SetPosition(1, swingPoint);
}
}
}using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public Transform target;
public Vector3 offset = new Vector3(0, 5, -10);
public float smoothSpeed = 0.125f;
void LateUpdate()
{
Vector3 desiredPosition = target.position + offset;
Vector3 smoothed = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
transform.position = smoothed;
transform.LookAt(target);
}
}Editor is loading...
Leave a Comment