I want to make a 'teleport' spell...

Hello kind souls! I’ve been studying programming for 6 months now (of an 2 years long education). I’m still pretty new to C#, and my dream is to be able to create small games (especially roguelikes). I’m currently trying to making one. I’ve my player movement, and enemies that follow you when you move. I’ve two spells, a attack spell (that doesn’t do anything right now) and a heal spell. Now I want to make a teleport spell that teleports you when you press ‘Alpha 3’.Much in the same veins as Diablo 1’s Phasing spell - you teleport randomly, you can’t control it. How do I make a spell like that?

using UnityEngine;
using System.Collections;

public class PhasingClass : MonoBehaviour {
	private Transform Phasing;
	public int phaseSpeed = 1;

	// Use this for initialization
	void Start () {
		Phasing = transform;
	}
	
	// Update is called once per frame
	void Update () {
		Phasing.Translate (Vector3.up * phaseSpeed * Time.deltaTime);
		
		// Destroy the object
		if (Phasing.position.y >= 0)
		{
			DestroyObject(gameObject);
		}
		else if (Phasing.position.x <= 0)
		{
			DestroyObject(gameObject);
		}
		else
		{
			DestroyObject(gameObject);
		}
	}
}

And in the player class:

if(Input.GetKeyDown(KeyCode.Alpha3))
			{
				//Under construction... Add cooldown and so on
				Phasing.transform.position = myPosition;
				transform.position = new Vector3(transform.position.x, transform.position.y + 0.7f, transform.position.z);
				Instantiate(Phasing);
			}

I’m eagerly awaiting your wisdom!

I don’t know about diablo BUT wth, …

you aren’t trying to teleport at all, …

actually you are trying to jump for 0.7m (or teleport for 0.7m up)

IF you want it randomly, … make empty gameobjects with tag whatever.

than when you want to teleport to that GO just do:

if(Input.GetKeyDown(KeyCode.Alpha3)){
    GameObject[] GOs = GameObject.FindGameObjectsWithTag("Whatever");
    int i = Random.Range(0, GOs.Length);
    transform.position = GOs*.transform.position;*

}
there are many ways to teleport, infact every movement in programming is actually teleporting.
Try not to think advanced just do basic stuff and learn basics that’s how I learned allot.
in 1 year of learning I already did 2 gr8 games (1 month and 1.5 month) other time I’m doing bigger project.
AND ofc I had no education behind me just self learning.

I unfortunately haven’t played the original Diablo. However, a very (and I mean very) simple teleport spell can be done in a snap by generating a random position vector and then moving to it. Something like this would suffice (written in C-Sharp).

using UnityEngine;
using System.Collections;

public class Teleport : MonoBehaviour
{
	private const KeyCode teleportButton = KeyCode.Alpha3;
	public Vector3 teleportPosition = new Vector3(0.0f, 0.0f, 0.0f);
	public Vector3 teleportRange = new Vector3(50.0f, 0.0f, 50.0f);

	// Use this for initialization
	void Start ()
	{

	}
	
	// Update is called once per frame
	void Update ()
	{
		if (Input.GetKeyDown(teleportButton))
		{
			float randomX = Mathf.Lerp(teleportPosition.x - teleportRange.x / 2.0f, teleportPosition.x + teleportRange.x / 2.0f, Random.value);
			float randomY = Mathf.Lerp(teleportPosition.y - teleportRange.y / 2.0f, teleportPosition.y + teleportRange.y / 2.0f, Random.value);
			float randomZ = Mathf.Lerp(teleportPosition.z - teleportRange.z / 2.0f, teleportPosition.z + teleportRange.z / 2.0f, Random.value);
			transform.position = new Vector3(randomX, randomY, randomZ);
		}
	}
}

In this script, the public variables teleportPosition and teleportRange control the whereabouts of the GameObject upon teleportation. The variable teleportButton holds which key is pressed to teleport. The actual teleportation happens in the Update method; upon pressing the teleport button, three random floats are generated. The GameObject that this script is attached to is then moved to it’s new position, which is determined by the three floats previously generated (each one corresponds to an axis).

This is the bare minimum for what you’d need to move to a random space upon pressing a button. You’d have to put a lot more into it for things like cast times, particle effects, sounds, animations and other aesthetics that I’m sure Diablo would have. Also, even though I haven’t played the old Diablo, I’d imagine it would use some sort of tile system similar to that of StarCraft. You might want to look into that. Good luck with your game! :smiley: