Spooder man
unknown
javascript
2 years ago
1.5 kB
10
Indexable
using UnityEngine;
public class SpooderManController : MonoBehaviour
{
public float swingForce = 10f;
public float moveSpeed = 5f;
public Transform webAnchor;
public LayerMask groundLayer;
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
// Web-swinging controls
if (Input.GetButtonDown("Jump") && IsGrounded())
{
Vector3 swingDirection = (webAnchor.position - transform.position).normalized;
rb.AddForce(swingDirection * swingForce, ForceMode.Impulse);
}
// Movement controls
float horizontalMove = Input.GetAxis("Horizontal");
float verticalMove = Input.GetAxis("Vertical");
Vector3 moveDirection = new Vector3(horizontalMove, 0f, verticalMove).normalized;
rb.MovePosition(rb.position + moveDirection * moveSpeed * Time.deltaTime);
}
bool IsGrounded()
{
return Physics.Raycast(transform.position, Vector3.down, 0.1f, groundLayer);
}
}
using UnityEngine;
public class EnemyController : MonoBehaviour
{
public float moveSpeed = 3f;
void Update()
{
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
Debug.Log("Spooder-Man caught by enemy!");
// Handle what happens when the player is caught by the enemy
}
}
}
Editor is loading...
Leave a Comment