So concerning this code in the DirectionalTargeting:
public override void StartTargeting(AbilityData data, Action finished)
{
RaycastHit raycastHit;
Ray ray = PlayerController.GetMouseRay();
if (Physics.Raycast(ray, out raycastHit, 1000, layerMask))
{
data.SetTargetedPoint(raycastHit.point + ray.direction * groundOffset / ray.direction.y);
}
finished();
}
The ground offset doesn’t seem correct. At least not for me, granted my camera angle is different than Sam/Rick’s game. I’ve got my camera closer to an isometric ARPG angle. Either way, when I shoot a projectile ability, as the cursor get’s closer to my player character, the projectile starts hitting the ground earlier. It never manages to travel just straight without a rotation in the Y. Regardless of how close the cursor is to the spawn point I would like it to travel at a constant Y height, AND pass through the where the cursor is clicked. Any thoughts or ideas?
Further away, projectile stays “above ground” longer
Closer to player, and projectile crosses ground plane sooner (obfuscated by the gate there).
I’ve tried getting the angle some other ways, like more explicitly stepping through the trig functions, but it leads to no different results at all. Just wondering if anyone has any thoughts.
Here’s the spawnprojectile ability
public class SpawnProjectileEffect : EffectStrategy
{
[SerializeField] Projectile projectileToSpawn;
[SerializeField] float damageAmount;
[SerializeField] bool isRightHand = true;
[SerializeField] bool useTargetPoint = true;
[SerializeField] bool isWeaponBased = true;
[SerializeField] float weaponDamageFraction = 0.25f;
public override void StartEffect(AbilityData data, Action finished)
{
Fighter fighter = data.GetUser().GetComponent<Fighter>();
Vector3 spawnPosition = fighter.GetHandTransform(isRightHand).transform.position;
if(useTargetPoint)
{
SpawnProjectileForTargetPoint(data, spawnPosition);
}
else
{
SpawnProjectilesForTargets(data, spawnPosition);
}
finished();
}
private void SpawnProjectileForTargetPoint(AbilityData data, Vector3 spawnPosition)
{
if (isWeaponBased)
{
PlayerController playerController = data.GetUser().GetComponent<PlayerController>();
damageAmount = GetWeaponDamage(playerController) * weaponDamageFraction;
}
Projectile projectile = Instantiate(projectileToSpawn);
projectile.transform.position = spawnPosition;
projectile.SetTarget(data.GetTargetedPoint(), data.GetUser(), damageAmount);
}
private void SpawnProjectilesForTargets(AbilityData data, Vector3 spawnPosition)
{
foreach (var target in data.GetTargets())
{
Health health = target.GetComponent<Health>();
if (health)
{
Projectile projectile = Instantiate(projectileToSpawn);
projectile.transform.position = spawnPosition;
projectile.SetTarget(health, data.GetUser(), damageAmount);
}
}
}
private float GetWeaponDamage(PlayerController playerController)
{
return playerController.GetComponent<Fighter>().GetCurrentWeaponDamage();
}
}
and the projectile class’ Update method, and settarget:
void Update()
{
if (target != null && isHoming && !target.IsDead())
{
transform.LookAt(GetAimLocation());
}
transform.Translate(Vector3.forward * speed * Time.deltaTime);
// MoveProjectile();
}
public void SetTarget(Health target, GameObject instigator, float damage)
{
SetTarget(instigator, damage, target);
}
public void SetTarget(Vector3 targetPoint, GameObject instigator, float damage)
{
SetTarget(instigator, damage, null, targetPoint);
}
public void SetTarget(GameObject instigator, float damage, Health target = null, Vector3 targetPoint = default)
{
this.target = target;
this.targetPoint = targetPoint;
this.damage = damage;
this.instigator = instigator;
Destroy(gameObject, maxLifeTime);
}
Any ideas about what could be causing this issue?