I have a little random script I am messing with and I can’t figure out how to make it ONLY jump when it is TOUCHING something.
Here is my code:
[/code]
I have a little random script I am messing with and I can’t figure out how to make it ONLY jump when it is TOUCHING something.
Here is my code:
[/code]
I also made a fun little Look script if you want to try it
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LookAim : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
[SerializeField] private Transform ObjectToLookAt;
// Update is called once per frame
void Update()
{
Vector3 DirectionToFace = ObjectToLookAt.localPosition - transform.localPosition;
transform.rotation = Quaternion.LookRotation(DirectionToFace);
Debug.DrawRay(transform.position, DirectionToFace, Color.red);
Quaternion targetRotation = Quaternion.LookRotation(DirectionToFace);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime);
}
}
just place in the object you want to look at and BOOM
sorry I forgot the code in the first part
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FireSpirit : MonoBehaviour
{
public int jumpPower = 500;
public int speed = 1000;
[SerializeField] ParticleSystem jumpFX;
Rigidbody rigidBody;
// Start is called before the first frame update
void Start()
{
rigidBody = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
Jump();
Move();
}
private void Move()
{
if (Input.GetKey(KeyCode.W))
{
rigidBody.AddRelativeForce(Vector3.forward * speed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.A))
{
rigidBody.AddRelativeForce(Vector3.left * speed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.S))
{
rigidBody.AddRelativeForce(Vector3.back * speed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.D))
{
rigidBody.AddRelativeForce(Vector3.right * speed * Time.deltaTime);
}
}
private void Jump()
{
{
if (Input.GetKeyDown(KeyCode.Space))
{
rigidBody.AddRelativeForce(Vector3.up * jumpPower);
}
}
}
}