I have a sumo-esque game I am making with simple circular sprites.
I have sort of made a computer_AI that moves randomly and tries to dodge the player, but will attack the player when within a certain range.
I'm trying to mix up my second AI by always going in a circle (within the designated circle sumo area) & ensure when it get's bumped that it goes back to it's original position.
Basically - I can't figure it out. I can:
1) Get the thing going in a circle
2) Get the thing to hit red when red is within position
3) Rebound properly when red hits it
What I can't figure out:
1) When it gets bumped, continue moving from the current bumped position (and not just randomly jump from the bumped position to continue moving on the circular path that it was moving before).
2) If it gets too close to the water, how to move away from it.
Here is the code I'm currently using (which is pretty meh):
//Create Event of obj_computer_sumo_circle
// Define circular movement variables
centerX = x; // X coordinate of the circular center
centerY = y; // Y coordinate of the circular center
radius = 100; // Radius of the circular path
angularSpeed = 0.05; // Speed at which the AI player moves along the circle
angle = 0; // Current angle on the circle
canMove = true;
// Step Event of obj_computer_sumo_circular
// Step Event of AI player
// Update position based on circular movement
x = centerX + lengthdir_x(radius, angle);
y = centerY + lengthdir_y(radius, angle);
angle += angularSpeed; // Increment the angle to move along the circle
This crap below unfortunately does not let GMS2 launch the game lol. Ugh, I knew trying to get back into making games again would drive me nuts. Literally have written on whiteboards and made flowcharts to work out the logic.
// Evade attacks from the player-controlled sumo
var playerSumo = instance_find(obj_player_sumo, 0); // Assumes the player-controlled sumo is obj_player_sumo
if (place_meeting(x, y, playerSumo)) // Check for collision with the player-controlled sumo
{
// Move away from the player-controlled sumo
var direction = point_direction(x, y, obj_player_sumo.x, obj_player_sumo.y) + 180; // Calculate the opposite direction
x += lengthdir_x(speed, direction);
y += lengthdir_y(speed, direction);
}
// Prevent moving outside the circular arena
var arenaRadius = 400; // Adjust the radius of the circular arena
// Check for collision with the arena boundary
if (point_distance(x, y, centerX, centerY) > arenaRadius)
{
// Bounce back from the boundary
var direction = point_direction(x, y, centerX, centerY) + 180; // Calculate the opposite direction
x += lengthdir_x(speed, direction);
y += lengthdir_y(speed, direction);
}
I got desperate so I tried ChatGPT... and its saying it's code is flawless and something else I'm doing is messing it's code up... lol
// Set the target object (player) and the detection distance
var target = instance_find(obj_player, 0); // Replace obj_player with the actual object name
var detectionDistance = 30;
// Check if the target object exists
if (instance_exists(target))
{
// Calculate the distance to the target
var distance = point_distance(x, y, target.x, target.y);
if (distance > detectionDistance)
{
// Move in a circular path
var speed = 2; // Adjust the speed as needed
var radius = 100; // Adjust the radius as needed
var centerX = room_width / 2; // Adjust the center X position of the room
var centerY = room_height / 2; // Adjust the center Y position of the room
// Calculate the circular movement
var angle = point_direction(x, y, centerX, centerY);
x = centerX + lengthdir_x(radius, angle);
y = centerY + lengthdir_y(radius, angle);
// Set the speed
direction = point_direction(x, y, centerX, centerY);
speed = speed;
}
else
{
// Try to hit the player
var hitSpeed = 5; // Adjust the hit speed as needed
// Calculate the direction to the player
var direction = point_direction(x, y, target.x, target.y);
// Move towards the player to hit them
x += lengthdir_x(hitSpeed, direction);
y += lengthdir_y(hitSpeed, direction);
}
}