#but interaction would require the
1 messages · Page 1 of 1 (latest)
Ok that's easier to track thanks
one: decide if you are currently looking at a valid interactable
so, raycast, try to get the component, and then check if you can interact with that component
if all of those are true, store that component into newInteractable
if any of those fail, store null into it
compare this to lastInteractable
once you're done, set lastInteractable = newInteractable;
Ok checking now
none of this logic depends on the last frame's interactable
so it should all be done before you even do anything with lastInteractable
if i'm following, the TryGet would be the last thing checked in the operation?
no. you can't check if CanInteract is true before you get the IInteractable component.
- see if the raycast hits anything
- if it does, see if that object has an
IInteractablecomponent - if it does, see if
CanInteractis true
Would this be the proper format for the function itself?
public bool CanInteract(GameObject interactedObject)
{
return interactedObject;
}
well, probably not
that literally just tells you if interactedObject is a valid object
You've written this several times now
iInteract.CanInteract(hit.collider.gameObject);
This does nothing.
You're just asking if you can interact and then doing nothing with that information.
ah, is it more like if(iInteract.CanInteract(hit.collider.gameObject)){
sure
although I feel like CanInteract should take something else as an argument...
hit.collider.gameObject is just the game object that the IInteractable is on
that's not very interesting information
I'd expect something more like this
if (player.CanInteract(iInteract))
asking the player if they are able to interact with this thing
is that still a bool function?
also, is this task more advanced? it doesn't seem beginner friendly
it's got a bool return type, so sure
you can always fill in more complex logic later
when you say player do you mean the player class contains a CanInteract type function?
rather than callback from the interacted interface?
rn its iInteract.CanInteract() which is called by the TryGetComponent
Yes. It seems reasonable to me that the player would know if it can or can't interact with something.
I guess you could also ask the interactable if you can interact with it
Either way works.
hmm good point, which one is less prone to error and more extendable you think?
ah so interface is probably best, that makes sense
a door might check if you have a key in your inventory
is it still GameObject then?
i don't know how your game works so I can't say what to actually pass it right now
probably a Player or something
if you have no idea what to put there, then just get rid of it for now
you can add this logic later when you have a better idea of what will and won't let you interact with something
Ah, so the player input manager class throws out a raycast which hits an object with the Iinteractable interface, which triggers the CanInteract