Making A First Person Slingshot
Hi guys. I've never worked on anything like this before, so I'm not entirely sure how to approach it. Basically, I'd like to create a slingshot that feels good to use and works well for accuracy. Insight on making a good elastic effect, reliable accuracy, general mechanics or any unity features I should know about would be very helpful.
links to games or tutorials would also be appreciated.
So far, I've only prototyped a quick and very crude working slingshot, which doesn't capture the feel I'm looking for. So again, any insight on this subject would be very helpful. Thank You
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Slingshot : MonoBehaviour {
public Transform launchPosition;
public Transform projectile;
public Transform initialPos;
bool launched = false;
public float force = 1000;
RaycastHit hit;
private void Start()
{
}
void Update()
{
if (Input.GetMouseButton(0) && !launched)
{
projectile.position = Vector3.Lerp(projectile.position, launchPosition.position, 1 * Time.deltaTime);
}
if (Input.GetMouseButtonUp(0))
{
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit))
{
projectile.rotation = Quaternion.LookRotation(hit.point - projectile.position);
projectile.GetComponent<Rigidbody>().isKinematic = false;
projectile.GetComponent<Rigidbody>().AddForce(projectile.forward * force * (Vector3.Distance(initialPos.localPosition, projectile.localPosition) / Vector3.Distance(initialPos.localPosition, launchPosition.localPosition)));
projectile.parent = null;
launched = true;
}
else
{
Debug.Log(Vector3.Distance(initialPos.localPosition, projectile.localPosition) / Vector3.Distance(initialPos.localPosition, launchPosition.localPosition));
projectile.GetComponent<Rigidbody>().isKinematic = false;
projectile.GetComponent<Rigidbody>().AddForce(projectile.forward * force * (Vector3.Distance(initialPos.localPosition, projectile.localPosition) / Vector3.Distance(initialPos.localPosition, launchPosition.localPosition)));
projectile.parent = null;
launched = true;
}
}
if (Input.GetMouseButtonDown(1))
{
projectile.position = initialPos.position;
projectile.rotation = initialPos.rotation;
projectile.parent = transform;
projectile.GetComponent<Rigidbody>().isKinematic = true;
launched = false;
}
}
}
Your answer
Follow this Question
Related Questions
C# FPS Speed Boost 0 Answers
Basic FPS help! 2 Answers
Multiplayer FPS version of unity networking tutorial? Using rigidbodies- see project link 0 Answers
How to make projectile to shoot in a sine wave pattern 1 Answer
2.5D Projectile Help 1 Answer