unity – Why the enemy is flipping constantly when it collides with an obstacle?

I’m making a 2D platformer with Unity. I have an enemy patrol that shoots bullet. The enemy is working fine until it reaches to a point that should be turn around. (when collides with an obstacle or is near the ledges) The problem is that the enemy flips rapidly in this situation. Also it only shoots to the right despite its facing direction. I’m pretty sure that the problem is from either the bullet or the pistol script because the enemy completely works when the pistol game object is disabled. My goal is to make the enemy flip at those points like before while it shoots the bullets in its facing direction.

Enemy script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Enemy : PhysicsObject
{
    (Header("Attributes"))
    private int direction = 1;
    (SerializeField) private float maxSpeed;
    (SerializeField) private LayerMask rayCastLayerMask; //Which layer do we want the raycast to interact with?
    (SerializeField) private Vector2 rayCastOffset; //Offset from the center of the raycast origin
    (SerializeField) private float rayCastLength = 2;
    bool isFacingLeft;

    (Header("References"))
    private RaycastHit2D rightLedgeRaycastHit;
    private RaycastHit2D leftLedgeRaycastHit;
    private RaycastHit2D rightWallRaycastHit;
    private RaycastHit2D leftWallRaycastHit;

    void Update()
    {
        targetVelocity = new Vector2(maxSpeed * direction, 0);

        if (targetVelocity.x < -.01)
        {
            transform.localScale = new Vector2(-1, 1);
            isFacingLeft = true;
        }
        else if (targetVelocity.x > .01)
        {
            transform.localScale = new Vector2(1, 1);
            isFacingLeft = false;
        }

        //Check for right ledge!
        rightLedgeRaycastHit = Physics2D.Raycast(new Vector2(transform.position.x + rayCastOffset.x, transform.position.y + rayCastOffset.y), Vector2.down, rayCastLength);
        Debug.DrawRay(new Vector2(transform.position.x + rayCastOffset.x, transform.position.y + rayCastOffset.y), Vector2.down * rayCastLength, Color.blue);
        if (rightLedgeRaycastHit.collider == null) direction = -1;

        //Check for left ledge!
        leftLedgeRaycastHit = Physics2D.Raycast(new Vector2(transform.position.x - rayCastOffset.x, transform.position.y + rayCastOffset.y), Vector2.down, rayCastLength);
        Debug.DrawRay(new Vector2(transform.position.x - rayCastOffset.x, transform.position.y + rayCastOffset.y), Vector2.down * rayCastLength, Color.green);
        if (leftLedgeRaycastHit.collider == null) direction = 1;

        //Check for right wall!
        rightWallRaycastHit = Physics2D.Raycast(new Vector2(transform.position.x, transform.position.y), Vector2.right, rayCastLength, rayCastLayerMask);
        Debug.DrawRay(new Vector2(transform.position.x, transform.position.y), Vector2.right * rayCastLength, Color.red);
        if (rightWallRaycastHit.collider != null) direction = -1;

        //Check for left wall!
        leftWallRaycastHit = Physics2D.Raycast(new Vector2(transform.position.x, transform.position.y), Vector2.left, rayCastLength, rayCastLayerMask);
        Debug.DrawRay(new Vector2(transform.position.x, transform.position.y), Vector2.left * rayCastLength, Color.magenta);
        if (leftWallRaycastHit.collider != null) direction = 1;
    }
}

Pistol script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Pistol : MonoBehaviour
{
    (SerializeField) GameObject bullet;
    (SerializeField) Transform bulletSpawnPos;
    private bool IsShooting;
  
   (SerializeField) private float shootDelay = .5f;
    private bool isFacingLeft;

    void Update()
    {
        if (IsShooting) return;
        IsShooting = true;
        GameObject b = Instantiate(bullet);
        b.GetComponent<Bullet>().StartShoot(isFacingLeft);
        b.transform.position = bulletSpawnPos.transform.position;
        Invoke("ResetShoot", shootDelay);
    }

  void ResetShoot()
    {
        IsShooting = false;
    }
}

Bullet script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bullet : MonoBehaviour
{
    (SerializeField) float speed;
    (SerializeField) int damage;
    float timeToDestroy = 3;

    public void StartShoot(bool isFacingLeft)
    {
        Rigidbody2D rb = GetComponent<Rigidbody2D>();

        if (isFacingLeft)
        {
            rb.velocity = new Vector2(-speed, 0);
        }
        else
        {
            rb.velocity = new Vector2(speed, 0);
        }

        Destroy(gameObject, timeToDestroy);
    }
}

java – A* algorithm: need help fixing path that come in contact with obstacle

I am using A* as a pathfinding technique for my AI; it works fine until it gets close to an obstacle (in my case rocks). Right now it just continues the loop if it finds a neighbor thats a rock. It should not actually do this. It should check it.

Allowed Moves: FORWARD,LEFT,RIGHT (LEFT & RIGHT at diagonals)

The AI should know to turn left or right on the rock in the direction of the goal while also taking other rocks into account.

The line that checks for rocks is: if(at == 1 || at == 2) continue;

I guess you could use the neighborlist to check the sides of the ship.

However it shouldn’t always check it. Only when it comes in contact with a rock

Scenario 1: (ship should turn left (one move) once then continue on path)
enter image description here

Scenario 2: (ship should either turn left or right twice (two moves) to unblock itself)
enter image description here

Scenario 3: (ship should turn left or right depending on which path is shorter: doing two lefts will hit rock twice but distance is shorter than if it went right by 1 tile)

enter image description here

In each of these scenarios the face of the ship is the only thing that changes. If right/left were used in any other situation (regular tiles) it would change position also.

public class AStarSearch {
    
    private ServerContext context;
    private List<AStarNode> openList;
    private List<AStarNode> closedList;
    
    private double ORTHOGONAL_COST = 1.0;
    private double DIAGONAL_COST = ORTHOGONAL_COST * Math.sqrt(2.0);
    
    public AStarSearch(ServerContext context) {
        this.context = context;
    }

    private Comparator<AStarNode> nodeSorter = new Comparator<AStarNode>() {

        @Override
        public int compare(AStarNode n0, AStarNode n1) {
            if(n1.fCost < n0.fCost) return 1;
            if(n1.fCost > n0.fCost) return -1;
            return 0;
        }
        
    };

    public List<AStarNode> findPath(Player bot, Position goal){
        openList = new ArrayList<AStarNode>();
        closedList = new ArrayList<AStarNode>();
        List<AStarNode> neighbors = new ArrayList<AStarNode>();
        AStarNode current = new AStarNode(bot, bot.getFace(), MoveType.NONE, null, 0, bot.distance(goal));
        openList.add(current);

        while(openList.size() > 0) {
            Collections.sort(openList, nodeSorter);
            current = openList.get(0);
            if(current.position.equals(goal)) {
                List<AStarNode> path = new ArrayList<AStarNode>();
                while(current.parent != null) {
                    path.add(current);
                    current = current.parent;
                }
                openList.clear();
                closedList.clear();
                Collections.reverse(path);
                return path;
            }
            openList.remove(current);
            closedList.add(current);
            
            int x = current.position.getX();
            int y = current.position.getY();
            switch (current.face) {
                case NORTH:
                    neighbors.add(new AStarNode(new Position(x, y), VesselFace.NORTH, MoveType.NONE,current,0,0));
                    neighbors.add(new AStarNode(new Position(x, y+1), VesselFace.NORTH, MoveType.FORWARD,current,0,0));
                    neighbors.add(new AStarNode(new Position(x-1, y+1), VesselFace.WEST, MoveType.LEFT,current,0,0));
                    neighbors.add(new AStarNode(new Position(x+1, y+1), VesselFace.EAST, MoveType.RIGHT,current,0,0));
                    break;
                case EAST:
                    neighbors.add(new AStarNode(new Position(x, y), VesselFace.EAST, MoveType.NONE,current,0,0));
                    neighbors.add(new AStarNode(new Position(x+1, y), VesselFace.EAST, MoveType.FORWARD,current,0,0));
                    neighbors.add(new AStarNode(new Position(x+1, y+1), VesselFace.NORTH, MoveType.LEFT,current,0,0));
                    neighbors.add(new AStarNode(new Position(x+1, y-1), VesselFace.SOUTH, MoveType.RIGHT,current,0,0));
                    break;
                case SOUTH:
                    neighbors.add(new AStarNode(new Position(x, y), VesselFace.SOUTH, MoveType.NONE,current,0,0));
                    neighbors.add(new AStarNode(new Position(x, y-1), VesselFace.SOUTH, MoveType.FORWARD,current,0,0));
                    neighbors.add(new AStarNode(new Position(x-1, y-1), VesselFace.WEST, MoveType.RIGHT,current,0,0));
                    neighbors.add(new AStarNode(new Position(x+1, y-1), VesselFace.EAST, MoveType.LEFT,current,0,0));
                    break;
                case WEST:
                    neighbors.add(new AStarNode(new Position(x, y), VesselFace.WEST, MoveType.NONE,current,0,0));
                    neighbors.add(new AStarNode(new Position(x-1, y), VesselFace.WEST, MoveType.FORWARD,current,0,0));
                    neighbors.add(new AStarNode(new Position(x-1, y+1), VesselFace.NORTH, MoveType.RIGHT,current,0,0));
                    neighbors.add(new AStarNode(new Position(x-1, y-1), VesselFace.SOUTH, MoveType.LEFT,current,0,0));
                    break;
            }
            for(AStarNode neighborNode : neighbors) {
                // Compute the cost to get *to* the action tile.
                double costToReach = current.position.distance(neighborNode.position);

                int at = context.getMap().getTile(neighborNode.position.getX(), neighborNode.position.getY());
                if(at == 1 || at == 2) continue; // this is the line where it checks if tile is rock or not

                double gCost = current.gCost + costToReach;
                double hCost = heuristicDistance(neighborNode.position,goal);
                AStarNode node = new AStarNode(neighborNode.position, neighborNode.face,neighborNode.move, current, gCost, hCost);
                if(positionInList(closedList, neighborNode.position) && gCost >= node.gCost) continue;
                if(!positionInList(openList, neighborNode.position) || gCost < node.gCost) openList.add(node);
            }
        }
        closedList.clear();
        return null;
    }
    
    private double getActionCost(Position node, int currentTile) {
        if(currentTile > 3 && currentTile < 11) {
            return 0.2;
        }else {
            return 1;   
        }
    }

    private double heuristicDistance(Position current, Position goal) {
        int xDifference = Math.abs(goal.getX() - current.getX());
        int yDifference = Math.abs(goal.getY() - current.getY());

        int diagonal = Math.min(xDifference, yDifference);
        int orthogonal = xDifference + yDifference - 2 * diagonal;

        return orthogonal * ORTHOGONAL_COST + diagonal * DIAGONAL_COST;
    }
    
    private boolean positionInList(List<AStarNode> list, Position position) {
        for(AStarNode n : list) {
            if(n.position.equals(position)) return true;
        }
        return false;
    }

}

AStarNode:

public class AStarNode {

    public Position position;
    public VesselFace face;
    public MoveType move;
    public AStarNode parent;
    public double fCost, gCost, hCost;
    
    public AStarNode(Position position, VesselFace face, MoveType move, AStarNode parent, double gCost, double hCost) {
        this.position = position;
        this.face = face;
        this.move = move;
        this.parent = parent;
        this.gCost = gCost;
        this.hCost = hCost;
        this.fCost = this.gCost + this.hCost;
    }
  
}  

The overall question/goal: How do I fix my current code to account for these situations; please provide an implementation or instructions.

2d – Path following with turning radius and obstacle avoidance

I would like to move an object through a path found by A* star but taking into account the object’s turn radius and movement speed, while also avoiding possible obstacles during a curve. After some research, I found this article in gamasutra about realistic turns and this question. If I understood correctly, to add smooth turns I just need to create a circle in either the left side of the object or the right (depending on which direction it will rotate) and then move the object along that circle until it reach the point in which it can move straight to the goal. I implemented the code from the article, however I couldn’t get it working

  • The tank is the object I want to move and the boxes are obstacles;
  • The red Xs are the “waypoints” and the blue line is the line segment
    between those points;
  • The white circle is the tank’s turning radius;
  • The green line is the actual movement the tank would perform taking
    its turning radius and movement speed into account;
  • And the pink
    dotted circle represents the “point to leave the circle and start on
    the straight line” that I’ve got with the algorithm;

https://i.imgur.com/XKVmOEn.png

The first problem is that I’m not sure how to calculate the right place for the pink circle. If I understood correctly, it should be positioned between the end of the green line’s curve and the start of the straight one.

The second problem is that, once solved the first, I don’t know how to actually move the tank through the “circular” path, while in straight path I could simply take the direction between the current point and the next, and move along that.

Here’s my implementation in gdscript

extends Node2D

var speed = 80
var rotation_speed = 1

var goal = null
var velocity = Vector2()


func _ready():
    goal = get_parent().get_node("Goal").global_position
    

func _physics_process(delta):
    if goal == null:
        return
    
    var pos = global_position
    var circle_radius = speed / rotation_speed
    
    var angle_to_circle_center = rotation + PI/2 #rotation - PI/2
    var circle_pos = pos
    circle_pos.x += circle_radius * cos(angle_to_circle_center)
    circle_pos.y += circle_radius * sin(angle_to_circle_center)
    
    var dx = goal.x - circle_pos.x
    var dy = goal.y - circle_pos.y
    var h = sqrt(dx*dx + dy*dy)
    var r = circle_radius
    
    if h < r:
        return
        
    var d = sqrt(h*h - r*r)
    var theta = acos(r / h)
    
    var phi = atan(dy / dx)
    var Q = Vector2()
    Q.x = circle_pos.x + r * cos(phi + theta)
    Q.y = circle_pos.y + r * sin(phi + theta)
    
    get_parent().get_node("icon").global_position = Q

Any insight would be appreciated – thanks in advance!

unreal 4 – How to create an obstacle that sends the player in the air?

I’m making a game in UE4.25 and I have several obstacles in there. I want them to send the player in the air if the player walks or stumbles into them. (Kind of like a Fall Guys effect, like if you get hit by a nearby falling ball, you fall into the void or something.)

Is there a possible way to do this?

dnd 5e – Telegraphing Encounter and Obstacle Characteristics for Preparation Casters

(Note: I feel that this question is sufficiently different from this one to justify a new post, as my question is about specific information informing Wizard spell preparation)

(Additional note: These same issues may be similarly relevant for other preparation casters. I chose to focus on Wizards because of my personal experiences as a player, my current needs as a DM, and the flexibility in access to spells that is unique to Wizards.

Please feel free to address this question for any preparation caster; Wizards simply have more opportunity to make “bad” choices in preparing spells due to their large spell list and greater number of spells known, while also having one of their key features be their versatility in what spells they can bring to a challenge)


One of the major class-balancing elements of the Wizard class is that they are only able to prepare a certain number of spells at a time. Among all magic using classes, wizards have access to the largest number of spells that they can learn, which makes them extremely versatile, but that versatility is tempered because they can only prepare a subset of those spells at any given time.

This can be very exciting– it adds a degree of planning, creativity, coordination, and tension to playing a wizard. It is also valuable in that it helps prevent the wizard from overshadowing other spellcasters with less expansive spell lists.

However, it can also be frustrating, particularly at lower levels when fewer spells can be prepared at once. It’s difficult to choose which spells to prepare if you don’t have any idea what challenges you’ll be facing, and even if you do have some information about that there may not be enough time to change which spells are prepared beforehand. It can be annoying to be completely mis-prepared for challenges.

Sometimes that’s appropriate: surprises do happen, narrow windows of opportunity may appear, and being maximally appropriately prepared for every encounter is not a realistic goal. Often there will be a middle ground, such as knowing you’ll be exploring an area rumored to be filled with undead enemies and so it might be a good idea to have spells that are useful against the undead.

But it’s not much fun to only rarely be able to use spells that you’ve learned specifically to deal with situations in which you find yourself because you didn’t (whether or not you couldn’t) know anything about what you’re walking into. Using magic to solve problems is largely what the Wizard class is about.

This has frustrated me as a player, and I’m having trouble balancing those concerns in a game I’m running now. If my approach to the issue is fundamentally that:

  • Surprising encounters can happen, particularly if my players drive
    those events
  • Events which are known in advance may not offer enough time to swap
    out prepared spells before dealing with them
  • Gathering advance knowledge about upcoming challenges won’t always be
    equally possible or reliable
  • Obtained knowledge about future challenges shouldn’t be a how-to
    guide on min-maxing those challenges
  • I don’t want to do away with the preparation mechanic
  • I don’t want to elide the issue by providing abundant spell scrolls
    or similar items

My experiences playing a wizard have been plagued by this issue, often leading me to wish I’d just chosen a different class. I’d like to spare my players that irritation if I can.

How can I telegraph enough information to a player with a preparation caster character (especially at lower levels) that they can avoid being totally mis-prepared, and how often should I do so?

dnd 5e – Telegraphing Encounter and Obstacle Characteristics for Wizards

(Note: I feel that this question is sufficiently different from this one to justify a new post, as my question is about specific information informing Wizard spell preparation)

One of the major class-balancing elements of the Wizard class is that they are only able to prepare a certain number of spells at a time. Among all magic using classes, wizards have access to the largest number of spells that they can learn, which makes them extremely versatile, but that versatility is tempered because they can only prepare a subset of those spells at any given time.

This can be very exciting– it adds a degree of planning, creativity, coordination, and tension to playing a wizard. It is also valuable in that it helps prevent the wizard from overshadowing other spellcasters.

However, it can also be frustrating, particularly at lower levels when fewer spells can be prepared at once. It’s difficult to choose which spells to prepare if you don’t have any idea what challenges you’ll be facing, and even if you do have some information about that there may not be enough time to change which spells are prepared beforehand. It can be annoying to be completely mis-prepared for challenges.

Sometimes that’s appropriate: surprises do happen, narrow windows of opportunity may appear, and being maximally appropriately prepared for every encounter is not a realistic goal. Often there will be a middle ground, such as knowing you’ll be exploring an area rumored to be filled with undead enemies and so it might be a good idea to have spells that are useful against the undead.

But it’s not much fun to only rarely be able to use spells that you’ve learned specifically to deal with situations in which you find yourself because you didn’t (whether or not you couldn’t) know anything about what you’re walking into. Using magic to solve problems is largely what the Wizard class is about.

This has frustrated me as a player, and I’m having trouble balancing those concerns in a game I’m running now. If my approach to the issue is fundamentally that:

  • Surprising encounters can happen, particularly if my players drive
    those events
  • Events which are known in advance may not offer enough time to swap
    out prepared spells before dealing with them
  • Gathering advance knowledge about upcoming challenges won’t always be
    equally possible or reliable
  • Obtained knowledge about future challenges shouldn’t be a how-to
    guide on min-maxing those challenges
  • I don’t want to do away with the preparation mechanic
  • I don’t want to elide the issue by providing abundant spell scrolls
    or similar items

My experiences playing a wizard have been plagued by this issue, often leading me to wish I’d just chosen a different class. I’d like to spare my players that irritation if I can.

How can I telegraph enough information to my wizard player (especially at lower levels) that they can avoid being totally mis-prepared, and how often should I do so?

Coronavirus is not an obstacle to win! – MLM and network marketing

Coronavirus? Super offer!

Shopifortunes: The ultimate night course on e-commerce!
Climb aboard the huge eCom craze that is sweeping the world!
Millions of people are researching online how to build their own successful online businesses and Shopify stores.
Shopifortunes teaches them how to do it! With hours of video footage taught by world-class experts, Shopifortunes is a very high-conversion instant messaging offering that sells like hotcakes!
Get all of our tools at https://bit.ly/2yX7DCE We have videos, articles, keywords, email scans and much more for you to be successful!
We want to see you crush it with this super spicy offer, and are ready to help you with anything you need! Make money together! Who knows? Maybe you will become a millionaire overnight!

the press does not hesitate https://bit.ly/2yX7DCE

.

What technical obstacle for Android does not support new versions of Java

I wonder why the version of Java no Android stays the same after so many years. However, the Kotlin is updated with a certain frequency, it is a technical problem the stagnation of the Java?

Obstacle Exchange in the Wild Worlds

So I've reached a fairly significant turning point in character development, which can lead to the potential situation where some of the obstacles I currently have no longer match the character.

I already did it once (sort of), with a minor drag – my PC was an alcoholic. However, the GM allowed me to remove this by attending AA meetings, etc. As long as I continue to prove my abstinence, I no longer "suffer" from alcoholism.

However, a story development appeared where the character potentially "made the choice" to actively change their perspectives. This is with regard to the "heroic" obstacle:

Your hero never says no to someone in need. She doesn't have to be happy about it, but she always comes to the rescue of those who she says cannot help themselves. She is the first to run in a burning building, usually agrees to hunt monsters for little or no pay, and is generally a push for a bloody story.

To sum up, the story has passed that there have been glimpses in the future where a person ended up enslaving the PC for its capabilities. And now, even if it seems that a particular future has been avoided, others are now invested in trying to use it for other purposes.

His point of view is that he will no longer tolerate this potential and will do whatever it takes to prevent it from happening. So I'm thinking of going from "Heroic" to "Vengeful (Major)"

Your character is still trying to make up for a wrong that they think has been done to them. If it is a minor obstruction, he usually seeks legal revenge. If this is a major obstacle, he will kill to do it.

So my question is; can I "change" my shackles, to RAW / RAI? If yes, what effect (s) does this have on my character?

dnd 5th – Line of sight, 5 foot parallel obstacle between the player and the enemy

I don't know what ability or what spell is causing this condition, but judging only by what you wrote, the player can easily hide behind the pillar – as long as the boss doesn't move.

Here's why:

Remember that players are usually medium-sized creatures. According to the player's manual, Ch 9: Size of the creature:

Each creature occupies a different amount of space. Size
Table of watch categories how much space a creature of a particular size
controls in combat
.

According to the table provided, an average creature (your player) controls 5 'x 5' space while fight. Does this mean that they physically occupy an entire 5 foot square? Of course not. For a concrete example, the doors of your house or apartment are generally 32 to 36 inches wide. Pretty easy to hide behind, right?

Therefore, a PC can easily hide behind a 5-foot diameter pillar to break the LOS to the boss. Now, if they can keep this broken line of sight, it's a whole different story!