Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NexusKitten/moremotion: Replace atan with atan2 #1880

Merged
merged 3 commits into from
Feb 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions extensions/NexusKitten/moremotion.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
},
},
extensions: ["colours_motion"],
hideFromPalette: true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GarboMuffin Oops? I'm pretty sure this block should be visible on the block palette.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think i have a comment in there that's also wrong, i said old version was 0-360 when its -90-270

},
{
filter: [Scratch.TargetType.SPRITE],
Expand Down Expand Up @@ -148,6 +149,24 @@
},
},
extensions: ["colours_motion"],
hideFromPalette: true,
},
{
filter: [Scratch.TargetType.SPRITE],
opcode: "directionto2",
blockType: Scratch.BlockType.REPORTER,
text: Scratch.translate("direction to x: [X] y: [Y]"),
arguments: {
X: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: "0",
},
Y: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: "0",
},
},
extensions: ["colours_motion"],
},
{
filter: [Scratch.TargetType.SPRITE],
Expand Down Expand Up @@ -257,21 +276,12 @@
util.target.setXY(util.target.x + x, util.target.y + y);
}

// LORAX APPROVED
pointto(args, util) {
const x = Scratch.Cast.toNumber(args.X);
const y = Scratch.Cast.toNumber(args.Y);
if (util.target.y > y) {
util.target.setDirection(
(180 / Math.PI) *
Math.atan((x - util.target.x) / (y - util.target.y)) +
180
);
} else {
util.target.setDirection(
(180 / Math.PI) * Math.atan((x - util.target.x) / (y - util.target.y))
);
}
util.target.setDirection(
(180 / Math.PI) * Math.atan2(x - util.target.x, y - util.target.y)
);
}

rotationStyle(args, util) {
Expand All @@ -287,6 +297,7 @@
}

directionto(args, util) {
// Old version, returns values from 0 to 360
const x = Scratch.Cast.toNumber(args.X);
const y = Scratch.Cast.toNumber(args.Y);
if (util.target.y > y) {
Expand All @@ -302,6 +313,13 @@
}
}

directionto2(args, util) {
// New version, returns values from -180 to 180, like Scratch direction reporter.
const x = Scratch.Cast.toNumber(args.X);
const y = Scratch.Cast.toNumber(args.Y);
return (180 / Math.PI) * Math.atan2(x - util.target.x, y - util.target.y);
}

distanceto(args, util) {
const x = Scratch.Cast.toNumber(args.X);
const y = Scratch.Cast.toNumber(args.Y);
Expand Down