CaithLynnSayes Posted April 23 Share Posted April 23 (edited) So i'm faffing around with a script for OpenSim. I like to slow down avatar speed to something more realistic because, yes, avatars walk too fast. Thankfully OS has an actual function for that but slowing down an avatar does make it struggle with slopes. It's not great going up hill. So my plan was to write a script that if an altitude change is detected while the avatar is walking, i should boost it's speed just a little bit. In order to do this, i had to add a little snippet to my script that actually detects the altitude change but unfortunately today i'm all but lazy. So i asked AI. Here's how that went: Me: Write me an LSL script that reports if an avatar is changing altitude while walking. AI: Certainly! Below is an LSL script that detects whether an avatar is changing altitude while walking. It utilizes the llGetAgentInfo function to determine if the queried avatar is walking. If the avatar is walking, it will play a sound (such as footsteps) to indicate movement: Quote integer gWasWalking; // TRUE when wearer is already walking string gSound = "footsteps"; // name of sound file in inventory default { state_entry() { // Start a timer to continuously check if the owner is walking llSetTimerEvent(0.25); } timer() { integer NowWalking = llGetAgentInfo(llGetOwner()) & AGENT_WALKING; if (NowWalking != gWasWalking) // walking has stopped or started { llStopSound(); if (NowWalking) llLoopSound(gSound, 1.0); // Play sound when walking } gWasWalking = NowWalking; } } You can place this script in a HUD (for the owner only to hear the sound) or in an attachment (for others to hear your footsteps too). Make sure to have a sound file named “footsteps” in the object’s inventory1. Feel free to customize the sound file to your preference! 🚶♀️🔊 Me: lol, that is not even close to what i asked. AI: I apologize for misunderstanding your initial request. Let me correct that. Here’s an LSL script that specifically checks if an avatar is changing altitude while walking: Quote integer gWasWalking; // TRUE when wearer is already walking default { state_entry() { // Start a timer to continuously check if the owner is walking llSetTimerEvent(0.25); } timer() { integer NowWalking = llGetAgentInfo(llGetOwner()) & AGENT_WALKING; if (NowWalking != gWasWalking) // walking has stopped or started { if (NowWalking) { // Avatar is walking, check altitude change vector startPos = llGetPos(); llSleep(0.1); // Wait a moment to get a new position vector endPos = llGetPos(); float altitudeChange = llVecDist(startPos, endPos).z; if (altitudeChange > 0.1) // Threshold for altitude change { llOwnerSay("Avatar is changing altitude while walking!"); } } } gWasWalking = NowWalking; } } In this revised script, I’ve added logic to detect altitude changes while the avatar is walking. If the avatar’s altitude changes significantly (more than 0.1 meters), it will report that the avatar is changing altitude while walking. Feel free to adjust the threshold value as needed! 🚶♀️📏 Me: there are errors in this script, fix it AI: I apologize for the oversight in the previous script. Let’s address the issues and provide a corrected version. Here’s the revised LSL script that accurately checks if an avatar is changing altitude while walking: Quote integer gWasWalking; // TRUE when wearer is already walking default { state_entry() { // Start a timer to continuously check if the owner is walking llSetTimerEvent(0.25); } timer() { integer NowWalking = llGetAgentInfo(llGetOwner()) & AGENT_WALKING; if (NowWalking != gWasWalking) // walking has stopped or started { if (NowWalking) { // Avatar is walking, check altitude change vector startPos = llGetPos(); llSleep(0.1); // Wait a moment to get a new position vector endPos = llGetPos(); float altitudeChange = llFabs(startPos.z - endPos.z); if (altitudeChange > 0.1) // Threshold for altitude change { llOwnerSay("Avatar is changing altitude while walking!"); } } } gWasWalking = NowWalking; } } In this corrected version: I’ve used llFabs to calculate the absolute value of the altitude change. The threshold for altitude change is set at 0.1 meters. You can adjust this value as needed. Feel free to use this updated script, and it should now accurately report altitude changes while an avatar is walking! 🚶♀️📏 Me: This works perfectly. Thanks! AI: You’re welcome! I’m glad the corrected script works as expected. If you have any more questions or need further assistance, feel free to ask. Happy scripting! 😊🚶♀️📏 (The AI in question here is Microsoft's Copilot. I've used ChatGPT in the past to generate LSL scripts but I've found that Copilot is just better at it, for now.) Edited April 23 by CaithLynnSayes Typo 1 Link to comment Share on other sites More sharing options...
Quistess Alpha Posted April 23 Share Posted April 23 for reference, here are my attempts at adjusting walking speed. 1 1 Link to comment Share on other sites More sharing options...
CaithLynnSayes Posted April 23 Author Share Posted April 23 37 minutes ago, Quistess Alpha said: for reference, here are my attempts at adjusting walking speed. I will have a look. Thanks. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now