Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-23-2012, 01:47 AM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Collision detection advice?

I'm working on a car script, and I'm having a lot of trouble figuring out how to stop the car from driving over a wall, and also being able to turn the car away from the wall and drive off again without the collision detection catching it and stopping it from moving.

Does anybody have any ideas about how to do this?

PHP Code:
//#CLIENTSIDE

const CAR_MAX 2;
const 
CAR_FRI 0.1;
const 
CAR_ACC 1.2;

function 
onCreated() {
  
this.angle 0;
  
client.incar false;
  
onTimeout();
}

function 
onPlayerChats() {
  if (
player.chat == "car") {
    
client.incar = !client.incar;
    
player.chat "Car:" SPC client.incar;
  }
}

function 
onTimeout() {
  if (
client.incar) {
    
freezeplayer(0.05);
    if (
keydown(0)) {
      
this.speed min(CAR_MAXmax(0.1CAR_ACC this.speed));
    } else {
      
this.speed *= (CAR_FRI);
    }
    if (
keydown(1)) this.angle -= 0.1;
    if (
keydown(3)) this.angle += 0.1;
    
    if (
client.stuck == true) {
      
this.angle += 0.2;
    }
    if (
player.dir == || player.dir == 2) {
      
temp.cpos = {player.0.5player.1};
      if (
onwall(cpos[0] - 2cpos[1] - 1) || onwall(cpos[0] + 4cpos[1] - 1) || onwall(cpos[0] + 4cpos[1] + 2) || onwall(cpos[0] - 2cpos[1] + 2)) {
        
//Stop from driving onto wall
      
} else {
        
player.-= sin(this.angle) * this.speed;
        
player.+= cos(this.angle) * this.speed;
      }
    } elseif (
player.dir == || player.dir == 3) {
      
temp.cpos = {player.0.5player.1};
      if (
onwall(cpos[0] - 3cpos[1] - 1.5) || onwall(cpos[0] + 6cpos[1] - 1.5) || onwall(cpos[0] + 6cpos[1] + 3.5) || onwall(cpos[0] - 2cpos[1] + 3.5)) {
        
//Stop from driving onto wall
      
} else {
        
player.-= sin(this.angle) * this.speed;
        
player.+= cos(this.angle) * this.speed;
      }
    }
    
player.dir getdir(-sin(this.angle), cos(this.angle));
  }
  
setTimer(0.05);

(Pardon the messy code. I'm yet to clean it up since I'm still working on it)

Also, is there a simpler method of checking for walls rather than checking for walls by calling onwall() a gazillion times?
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:19 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.