Hello guys,
I am doing a minor project for an exam, and I am currently a bit stuck.
The base of the game is just using Unity’s Roll-A-Ball tutorial. What I am doing for my exam, is trying to make a seperate kind of collectibles that requires the player to dash through them in order to pick up said collectible.
I got the collectible made, however I can’t figure out how to make the dash ability, actually only dash relative to the axes of the plane / ground, rather than the axes of the sphere when it is rolling…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Character.Abilities
{
public class DashAbility : Ability
{
[SerializeField] private float dashForce;
[SerializeField] private float dashDuration;
private Rigidbody rb;
private void Awake()
{
rb = GetComponent<Rigidbody>();
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
StartCoroutine(Cast());
}
}
public override IEnumerator Cast()
{
rb.AddForce(transform.forward * dashForce, ForceMode.VelocityChange);
yield return new WaitForSeconds(dashDuration);
rb.velocity = Vector3.zero;
}
}
}
I know that it is not supposed to use the transform.forward, hence why it’s using the axes of the rolling sphere. What I can’t seem to figure out is how to make it move relative to the ground.
Hope somebody can help me!