Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Car Movements Help (https://forums.graalonline.com/forums/showthread.php?t=134265038)

Gunderak 11-17-2011 07:47 AM

Never mind, it seems to be working on.
it was a problem when turning left with the angle going minus that was stuffing it.
I just set the start angle and it works fine now.
Now all I need to do is the characters head and im done.

Gunderak 11-17-2011 09:22 AM

I now have the cars rotation, player head rotation and now reversing.
Any idea's one how I could make something so if it hit a wall it would bounce back?
Well I know the bounce back bit.
In my script I have on a timeout if the speed is less than zero that it will slowly stop..
But how would the wall checks work for something like this?
the most complex part I know is if(onwall(x, y)){
Pretty sad eh?
To clarify it up for anyone that doesn't understand.
I am wondering how I could make something caculate if there is a wall I front of you and bounce you back.
How would you get all the on wall checks to work ^_~

fowlplay4 11-17-2011 04:24 PM

Use the same math you're using to move the car to check if that x, y position is on a wall. If it is then 'bounce back'.

Tricxta 11-17-2011 09:49 PM

You can invert the angle easily by doing

invertedangle=(angle+pi)%(pi*2)

as for the power, I would subtract a little from the initial collision. Then use the same direction formula you have already been given.

Gunderak 11-17-2011 11:12 PM

Thanks for the help, il get started on the collision checking when I get home.

cbk1994 11-17-2011 11:18 PM

Quote:

Originally Posted by Tricxta (Post 1674488)
You can invert the angle easily by doing

invertedangle=(angle+pi)%(pi*2)

as for the power, I would subtract a little from the initial collision. Then use the same direction formula you have already been given.

All you need to do is add pi to it, the sin and cos functions don't require it to be in [0, 2pi).

Tricxta 11-18-2011 08:06 AM

Quote:

Originally Posted by cbk1994 (Post 1674502)
All you need to do is add pi to it, the sin and cos functions don't require it to be in [0, 2pi).

I just like to keep things clean. Still,thanks for the info.

Gunderak 11-18-2011 08:54 AM

I know how to detect if there on a wall, but how would I handle it?
I have tried reversing the players movement which is this.
PHP Code:

    player.-= sin(this.angle) * this.speed;
    
player.-= cos(this.angle) * this.speed

But that doesn't work.
I think I'm in way over my head.

cbk1994 11-19-2011 03:32 AM

Quote:

Originally Posted by Tricxta (Post 1674538)
I just like to keep things clean. Still,thanks for the info.

You're not keeping it clean, you're just overcomplicating it and adding more work for the engine. It takes longer for a scripter to read and understand your code than it does mine.

Tricxta 11-19-2011 06:24 AM

Quote:

Originally Posted by Gunderak (Post 1674540)
I know how to detect if there on a wall, but how would I handle it?
I have tried reversing the players movement which is this.
PHP Code:

    player.-= sin(this.angle) * this.speed;
    
player.-= cos(this.angle) * this.speed

But that doesn't work.
I think I'm in way over my head.

That won't reverse the direction in which the player moves, instead do what chris said and just add pi to the existing angle.

Quote:

Originally Posted by cbk1994 (Post 1674607)
You're not keeping it clean, you're just overcomplicating it and adding more work for the engine. It takes longer for a scripter to read and understand your code than it does mine.

I meant variable wise, you're going to keep on adding onto your angle which will eventually become quite a large number if used for a while. Also while you do have a valid point I'm sure one extra mod and multiplication operator doesn't effect performance to the point where you'd notice on any machine. What if I wanted to see what was going on in the script and I had some huge messy number as the angle, it'd be pretty ugly to work with. Also by including mod and multiplication the angle can work with other formulas if you choose.

Also for those who don't know % is the mod operator. It works by spitting out the remainder of 2 given numbers. Eg:6%4=2, 6%5=1, 11%10=1

Gunderak 11-19-2011 06:36 AM

Update: I now have collision detection and it works.
Next up: When you fire the weapon it should put you in the car, when you press A it should place a NPC of the car on the map and allow you to press A next to it to enter.
@Everyone Thanks for all your help


All times are GMT +2. The time now is 06:00 AM.

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