Reputation: 3
I'm writing a script for my learning project, it's a 3D fireballs mobile game copy.
My task to implement a mechanic of ball bouncing back from an obstacle. There are simpler ways, but, unfortunately I have to use the one attached. When I try to use method Evaluate
I'm having this kind of log
1 In JB Rider it is:
Cannot resolve symbol 'Evaluate'
Assets\Scripts\Physics\DirectionalBounce.cs(56,48): error CS1061: 'Animation' does not contain a definition for 'Evaluate' and no accessible extension method 'Evaluate' accepting a first argument of type 'Animation' could be found (are you missing a using directive or an assembly reference?)
using System.Collections;
using Coroutines;
using Structures;
using UnityEngine;
namespace Physics
{
[System.Serializable]
public class DirectionalBouncePreferences
{
public float Duration;
public float Height;
public Animation Trajectory;
public DirectionalBouncePreferences(float duration, float height, Animation trajectory)
{
Duration = duration;
Height = height;
Trajectory = trajectory;
}
}
public class DirectionalBounce
{
private readonly Transform _bouncer;
private CoroutineExecutor _coroutineExecutor;
private readonly DirectionalBouncePreferences _preferences;
public DirectionalBounce(Transform bouncer, CoroutineExecutor coroutineExecutor, DirectionalBouncePreferences preferences)
{
_bouncer = bouncer;
_coroutineExecutor = coroutineExecutor;
_preferences = preferences;
}
public void BounceTo(Vector3 target, Vector3 startPosition) =>
_coroutineExecutor.Start(InerpolatePositionTo(target, startPosition));
private IEnumerator InerpolatePositionTo(Vector3 target, Vector3 startPosition)
{
var timer = new UnityTimer();
timer.Start(_preferences.Duration);
while (timer.IsTimeUp == false)
{
float t = timer.ElapsedTimePercent;
Vector3 newPosition = CalculatePosition(target, startPosition, t);
_bouncer.transform.position = newPosition;
yield return null;
}
}
private Vector3 CalculatePosition(Vector3 target, Vector3 startPosition, float t)
{
return Vector3.Lerp(startPosition, target, t) +
Vector3.up * _preferences.Trajectory.Evaluate(t) *
_preferences.Height;
}
}
}
[enter image description here][1]
Upvotes: 0
Views: 91
Reputation: 241858
The issue appears to be that you're calling a method named Evaluate
on an instance of an Animation
class - which does not have a method called Evaluate
.
Just a guess, but perhaps you were looking for AnimationCurve.Evaluate
?
Upvotes: 2