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.

Newcomers AppGameKit Corner / Keep a 3d object facing its linear velocity direction

Author
Message
RotaMafia
6
Years of Service
User Offline
Joined: 13th Oct 2017
Location: Portveien 2, Norway
Posted: 6th Feb 2022 02:33
Hi again all

Sorry if this gets too frequent but i had such a good experience last time when asking a question, that I choose to get in touch again.
I now need a function to always rotate a object to it's line of travel.
i am creating in a 3d world and using physics by setting linear velocity.
All is really going good, but i can't figure out how to use "SetObject3DPhysicsAngularVelocity".
As the objects can collide and move around it must update and rotate accordingly to its line of travel.
Please help me get the angular velocity correct and finally get these boids moving smoothly.
I am a novice in coding, all tips and tricks are more then welcome ! c",)






P.S. Made out of several tutorials on YouTube. Especially Daniel's tutorials at "The Coding Train".
But this is all my code. Feel free to explore and use as you wish and maybe you can figure it out
"I, for one love finding stuff like this. Let us share the fun"

Attachments

Login to view attachments
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 6th Feb 2022 05:58
you want the objects to gradually rotate to face their direction of travel as in this demo, right?

just making sure before i dive into another rabbit hole
RotaMafia
6
Years of Service
User Offline
Joined: 13th Oct 2017
Location: Portveien 2, Norway
Posted: 6th Feb 2022 07:23
Hi again @VirtualNomad
Yes that's exactly what I want. Kind of like a plane, fish or homing missile would be turning.
I have looked all over the forum, and the "push create" and "moving car" threads seem to be touching in on it.
But i can't figure it out

Its looks to be a hot topic on several threads usually ending with a "lookat" solution, but it feels kind of sad to leave it like this.
Being so close to perfect and all


OriginalKronos
6
Years of Service
User Offline
Joined: 10th Nov 2017
Location:
Posted: 9th Feb 2022 00:06 Edited at: 9th Feb 2022 00:22
--deleted-- Thought I'd done something clever then spotted you had already done it in the code...

Is not pressing the spacebar giving you the effect you wanted..They look pretty fishy.

I would add you could probably do with some spatial partitioning to efficiently calculate nearest boid neighbours as currently you are cycling through roughly 40000+ boids every loop which I think is why your demo is slow.
OriginalKronos
6
Years of Service
User Offline
Joined: 10th Nov 2017
Location:
Posted: 9th Feb 2022 00:15 Edited at: 9th Feb 2022 00:47
Can't really tell if this is an improvement or not to be honest but try deletiing the fixobjecttoobject in line 384 and replace line 300 with



only works for the coloured fish after pressing space. Movement seems a little less erratic but I could be wrong.
RotaMafia
6
Years of Service
User Offline
Joined: 13th Oct 2017
Location: Portveien 2, Norway
Posted: 9th Feb 2022 04:04 Edited at: 9th Feb 2022 04:33
Hi @OriginalKronos

They're pretty fishy but the problem is that thay do not "turn around".
Ex. i have made a test with food. when thay get close thay can do 180*degree with
no motion between the two positions.

What i am looking for is a solution to have them turn around gradually.
But i can't get it working. Hope to use: "SetObject3DPhysicsAngularVelocity".
Don't really understand how "SetObject3DPhysicsAngularVelocity" works. I have tried with
several approaches but nothing works. Sounds so easy.
"Just turn gradually based on the attached objects angle, or boids next vector position."
Feel like i am doing somthing wrong. Really appreciate any help on this!.

Hope to improve on the boid code as i go, but stuck on this for now.
The "display by pushing space" was just meant as a reference.
I use it to se effect of "SetObject3DPhysicsAngularVelocity" as
i test diffrent approaches :p

Thanks for your input OriginalKronos
really enjoy this forum
jd_zoo
5
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 11th Feb 2022 01:20
This looks awesome well done!

Login to post a reply

Server time is: 2024-04-23 23:04:22
Your offset time is: 2024-04-23 23:04:22