How would I make this Collider work better in Java?(it currently sticks to walls)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
if(getBounds().intersects(go.getBounds())) {
x += -velX;
y += -velY;
}
The getBounds() method returns a rectangle. The intersects() method checks if they intersect and sends true or false; these work perfectly. The problem with making both the x and y value add -velX and -velY is that it makes the object stick to the "go" object. I would like to be able to push up against the "go" object and still slide across it on the axis parallel to the face that is touching the object(pardon my shitty explaining).
java collision-detection
add a comment |
if(getBounds().intersects(go.getBounds())) {
x += -velX;
y += -velY;
}
The getBounds() method returns a rectangle. The intersects() method checks if they intersect and sends true or false; these work perfectly. The problem with making both the x and y value add -velX and -velY is that it makes the object stick to the "go" object. I would like to be able to push up against the "go" object and still slide across it on the axis parallel to the face that is touching the object(pardon my shitty explaining).
java collision-detection
1
It might be helpful to illustrate what you're asking, as well as what's currently happening.
– Jacob G.
Jan 3 at 16:14
In case of intersection you need to switch sign ofvelX
orvelY
depending on which wall you hit.
– Ivan
Jan 3 at 16:24
You basically have 2 points: where the object was, where it is now (insidego
). Then you have the geometry and coordinates ofgo
. Then you must calculate the 3rd point, where you want the object to end up. Draw these on paper. Then you need to do some basic 2D geometry calculations... Try working on this, adding more information (such as these drawings you need to do to sort it out in your head) and code (such as entire movement code) to the question.
– hyde
Jan 3 at 16:25
add a comment |
if(getBounds().intersects(go.getBounds())) {
x += -velX;
y += -velY;
}
The getBounds() method returns a rectangle. The intersects() method checks if they intersect and sends true or false; these work perfectly. The problem with making both the x and y value add -velX and -velY is that it makes the object stick to the "go" object. I would like to be able to push up against the "go" object and still slide across it on the axis parallel to the face that is touching the object(pardon my shitty explaining).
java collision-detection
if(getBounds().intersects(go.getBounds())) {
x += -velX;
y += -velY;
}
The getBounds() method returns a rectangle. The intersects() method checks if they intersect and sends true or false; these work perfectly. The problem with making both the x and y value add -velX and -velY is that it makes the object stick to the "go" object. I would like to be able to push up against the "go" object and still slide across it on the axis parallel to the face that is touching the object(pardon my shitty explaining).
java collision-detection
java collision-detection
edited Jan 3 at 16:19
hyde
32.2k1589133
32.2k1589133
asked Jan 3 at 16:12
Nolan DavenportNolan Davenport
1
1
1
It might be helpful to illustrate what you're asking, as well as what's currently happening.
– Jacob G.
Jan 3 at 16:14
In case of intersection you need to switch sign ofvelX
orvelY
depending on which wall you hit.
– Ivan
Jan 3 at 16:24
You basically have 2 points: where the object was, where it is now (insidego
). Then you have the geometry and coordinates ofgo
. Then you must calculate the 3rd point, where you want the object to end up. Draw these on paper. Then you need to do some basic 2D geometry calculations... Try working on this, adding more information (such as these drawings you need to do to sort it out in your head) and code (such as entire movement code) to the question.
– hyde
Jan 3 at 16:25
add a comment |
1
It might be helpful to illustrate what you're asking, as well as what's currently happening.
– Jacob G.
Jan 3 at 16:14
In case of intersection you need to switch sign ofvelX
orvelY
depending on which wall you hit.
– Ivan
Jan 3 at 16:24
You basically have 2 points: where the object was, where it is now (insidego
). Then you have the geometry and coordinates ofgo
. Then you must calculate the 3rd point, where you want the object to end up. Draw these on paper. Then you need to do some basic 2D geometry calculations... Try working on this, adding more information (such as these drawings you need to do to sort it out in your head) and code (such as entire movement code) to the question.
– hyde
Jan 3 at 16:25
1
1
It might be helpful to illustrate what you're asking, as well as what's currently happening.
– Jacob G.
Jan 3 at 16:14
It might be helpful to illustrate what you're asking, as well as what's currently happening.
– Jacob G.
Jan 3 at 16:14
In case of intersection you need to switch sign of
velX
or velY
depending on which wall you hit.– Ivan
Jan 3 at 16:24
In case of intersection you need to switch sign of
velX
or velY
depending on which wall you hit.– Ivan
Jan 3 at 16:24
You basically have 2 points: where the object was, where it is now (inside
go
). Then you have the geometry and coordinates of go
. Then you must calculate the 3rd point, where you want the object to end up. Draw these on paper. Then you need to do some basic 2D geometry calculations... Try working on this, adding more information (such as these drawings you need to do to sort it out in your head) and code (such as entire movement code) to the question.– hyde
Jan 3 at 16:25
You basically have 2 points: where the object was, where it is now (inside
go
). Then you have the geometry and coordinates of go
. Then you must calculate the 3rd point, where you want the object to end up. Draw these on paper. Then you need to do some basic 2D geometry calculations... Try working on this, adding more information (such as these drawings you need to do to sort it out in your head) and code (such as entire movement code) to the question.– hyde
Jan 3 at 16:25
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54025980%2fhow-would-i-make-this-collider-work-better-in-javait-currently-sticks-to-walls%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54025980%2fhow-would-i-make-this-collider-work-better-in-javait-currently-sticks-to-walls%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
It might be helpful to illustrate what you're asking, as well as what's currently happening.
– Jacob G.
Jan 3 at 16:14
In case of intersection you need to switch sign of
velX
orvelY
depending on which wall you hit.– Ivan
Jan 3 at 16:24
You basically have 2 points: where the object was, where it is now (inside
go
). Then you have the geometry and coordinates ofgo
. Then you must calculate the 3rd point, where you want the object to end up. Draw these on paper. Then you need to do some basic 2D geometry calculations... Try working on this, adding more information (such as these drawings you need to do to sort it out in your head) and code (such as entire movement code) to the question.– hyde
Jan 3 at 16:25