My game has a combat system where on the fourth hit it knocks the enemy back using tweenservice. But when the enemy gets knocked back it can go through objects. What would I have to do to make it so enemies can’t go through objects.
My game has a combat system where on the fourth hit it knocks the enemy back using tweenservice. But when the enemy gets knocked back it can go through objects. What would I have to do to make it so enemies can’t go through objects.
Tweens never calculate physics or collisions. You could try casting a ray from the hit player’s humanoid root part in the direction they’re going and checking if they’re touching/will touch a part. If true then you can stop the Tween. This would have to be done every frame that the hit player is being pushed. Alternatively, you could try using BodyMovers like BodyForce to push the player yet keep collisions.
When I cast a ray im able to check if the enemy is going to hit a part but how would I pause the tween when the enemy actually hits the part.
Tween:Pause()
will stop the Tween.
Don’t use Tweens for physics-related stuff. I implore you to use body movers for this sort of thing.
See info on BodyVelocity (a body mover) here.