Discuss Scratch

q0zz
Scratcher
3 posts

They won’t run from the predator.

I’m making a wildlife simulation where you can observe alien creatures survive in a small box. So far it’s new but it’s very glitchy. My main problem is how the Whinnies don’t avoid the Haggleworth and just move directly towards it. I also want it so all of them are heading towards their location (where they’re going) and not sidewalking like crabs.

If anyone could provide me a solution to have the prey avoid the predator instead of lining up on the edge then flying everywhere and dying, it would be great, as I am an inexperienced coder (only 1.5 years of scratch programming).

The project in question: https://scratch.mit.edu/projects/1217136446/
Koamodo975
Scratcher
1000+ posts

They won’t run from the predator.

janky garbage solution but you could make it so that if a whinny clone is close to the haggleworth, the whinny points towards it and turns randomly from 150-210 degrees, then runs away. should make them slightly smarter in the face of a predator
q0zz
Scratcher
3 posts

They won’t run from the predator.

Koamodo975 wrote:

janky garbage solution but you could make it so that if a whinny clone is close to the haggleworth, the whinny points towards it and turns randomly from 150-210 degrees, then runs away. should make them slightly smarter in the face of a predator

Looks a lot better as they’re making this cool zig zag motion, but there are way more deaths and they’re circling the predator even more.
10goto10
Scratcher
1000+ posts

They won’t run from the predator.

I think your distance comparisons are going the wrong way. I made this change to the script in whinny and at least it is not circling anymore. Many are still dying.

when I start as a clone
set rotation style [all around v]
forever
if <<[200] = (distance to [Haggleworth v])> or <[150] \> (distance to [Haggleworth v])>> then
repeat until <<(distance to [Haggleworth v]) = [160]> or <(distance to [Haggleworth v]) \> [160]>>
point towards [Haggleworth v]
turn @turnLeft (pick random (120) to (220)) degrees::motion
move (10) steps
end
else
repeat (pick random (30) to (60))
move (2) steps
if on edge, bounce
end
wait (1) seconds
end
end

I also changed the part where they turn away from Haggleworth to make sure that they turned away and I rotated the custume 90 degrees to fix their direction when moving.
Oneshot_Enthusiast
Scratcher
100+ posts

They won’t run from the predator.

Koamodo975
Scratcher
1000+ posts

They won’t run from the predator.

q0zz wrote:

Koamodo975 wrote:

janky garbage solution but you could make it so that if a whinny clone is close to the haggleworth, the whinny points towards it and turns randomly from 150-210 degrees, then runs away. should make them slightly smarter in the face of a predator

Looks a lot better as they’re making this cool zig zag motion, but there are way more deaths and they’re circling the predator even more.
ah probs cause they immediately just start turning randomly right after getting out of range. Try making it so that they repeatedly run away for a way if they get too close? it also looked like the whinnies have a 360 turn radius while they're wandering, you could narrow that down some so they walk in a usually general direction.

Powered by DjangoBB