Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [Tier 1] Trouble with ObjectSphereCast()

Author
Message
basicFanatic
6
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 20th Feb 2018 23:20
So, I have this code where I can "glue" a sphere to a cube, and unglue it too:




But I want to not just glue the sphere to the cube, but any object that the cube gets in contact with.
So I use ObjectSphereCast() to detect whatever object is in contact with the cube:

ObjectSphereCast( 0, AGKVR.GetRightHandX()-0.01, AGKVR.GetRightHandY()-0.01, AGKVR.GetRightHandZ()-0.01, AGKVR.GetRightHandX()+0.01, AGKVR.GetRightHandY()+0.01, AGKVR.GetRightHandZ()+0.01, 0.02)
if GetObjectRayCastNumHits() = TRUE // if an object is currently being hit ...
touchedObject = GetObjectRayCastHitID(0)

...But now, the object in contact with the cube (which is the same old sphere) suddenly gets positioned several meters away. It seems like I'm getting some wrong values. I think I had been in this mess before where it was something with getting the parents value or something. Anyway, my misbehaving code goes like this:

Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 21st Feb 2018 01:01
I notice that you are creating a 3D Physics world.
You do realize that the ObjectSphereCast() command
does not work with the 3D Physics commands, 2 different systems.
The coffee is lovely dark and deep,and I have code to write before I sleep.
basicFanatic
6
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 21st Feb 2018 06:36
Right! I copypasted from a project that did use physics, and totally forgot that it is a different thing. (should be pretty easy to keep apart, as one is found in Home > Commands > 3DPhysics and the other in Home > Commands > 3D.) So my error is not found in that 3DPhysics code, as it does (kinda) absolutely nothing.
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 21st Feb 2018 10:02
What happens if you just fix the object as soon as a collision is detected without trying to reposition it?
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
basicFanatic
6
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 21st Feb 2018 12:12
Thanks, tried, but no change whatsoever!
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 21st Feb 2018 19:12
your code is fine you just moved the controller object to 0,0,0 before you work out it's position
so change to this and it works
// Hide the controller so we don't hit it:
//SetObjectPosition( rightControllerObject, 0, 0, 0)
SetObjectCollisionMode(rightControllerObject,0)
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
puzzler2018
User Banned
Posted: 21st Feb 2018 19:15
maybe

fixobjecttoibject and setobjectshapestaticpolygon

basicFanatic
6
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 22nd Feb 2018 00:26
@smallg:
You cracked it! This makes perfect sense. Finally I can move on!

@puzzler2018:
Sorry, didn't get your point! Could just be being way sleepy.

Goodnight folks!

Login to post a reply

Server time is: 2024-04-25 14:36:58
Your offset time is: 2024-04-25 14:36:58